gapi.cloudsearch.widget.searchbox.Builder
搜尋框的建構工具。請使用建構工具,不要直接呼叫 SearchBox 建構函式。
建構函式
Builder
new Builder()
示例
// Builds a search box.
function onload() {
gapi.client.init({
'apiKey': '<your api key>',
'clientId': '<your client id>',
// Add additional scopes if needed
'scope': 'https://www.googleapis.com/auth/cloud_search.query',
'hosted_domain': '<your G Suite domain>',
});
const searchBox = new gapi.cloudsearch.widget.searchbox.Builder()
.setInput(document.getElementById('input'))
.setAnchor(document.getElementById('input').parentElement)
.build();
}
gapi.load('client:cloudsearch-widget', onload);
方法
build
build() 會傳回 SearchBox
- 傳回
-
non-null SearchBox
setAdapter
setAdapter(adapter) 會傳回 Builder
必填。使用這個轉接程式自訂使用者的搜尋體驗。
參數 |
|
---|---|
adapter |
您可以覆寫部分方法。 值不得為空值。 |
- 傳回
-
non-null Builder
this
示例
const adapter = {
interceptSuggestRequest: function(request) {
// Change the request
}
}
builder.setAdapter(adapter).build();
setAnchor
setAnchor(anchor) 會傳回 Builder
必填。必須是可包含子節點的有效 HTMLElement。搜尋覆疊層的錨點。重疊層會新增為錨點中的最後一個子項。重疊圖層的位置是錨點的底部。
參數 |
|
---|---|
anchor |
HTMLElement 值不得為空值。 |
- 已淘汰
- 請改用 `setAnchorElement`
- 傳回
-
non-null Builder
this
setAnchorElement
setAnchorElement(anchorElement) 會傳回 Builder
必填。必須是可包含子節點的有效 HTMLElement。搜尋覆疊層的錨點。重疊層會新增為錨點中的最後一個子項。重疊圖層的位置是錨點的底部。
參數 |
|
---|---|
anchorElement |
HTMLElement 值不得為空值。 |
- 傳回
-
non-null Builder
this
setHints
setHints(hints) 會傳回 Builder
(選用) 輸入內容為空白時,搜尋框上的提示。 如果輸入內容為空白,系統會從陣列中隨機挑選提示。
參數 |
|
---|---|
提示 |
字串陣列 值不得為空值。 |
- 傳回
-
non-null Builder
this
setInput
setInput(input) 會傳回 Builder
必填。使用者輸入查詢的 HTMLElement。必須是 <input> 或 <textarea>
參數 |
|
---|---|
輸入 |
HTMLElement 值不得為空值。 |
- 已淘汰
- 改用 `setInputElement`
- 傳回
-
non-null Builder
this
setInputElement
setInputElement(inputElement) 會傳回 Builder
必填。使用者輸入查詢的 HTMLElement。必須是 <input> 或 <textarea>
參數 |
|
---|---|
inputElement |
HTMLElement 值不得為空值。 |
- 傳回
-
non-null Builder
this
setResultsContainer
setResultsContainer(resultsContainer) 會傳回 Builder
(選用) 用於顯示搜尋結果的容器。如果已設定,結果就會在搜尋結果容器中顯示。 如未設定,結果會顯示在 cloudsearch.google.com 中。
參數 |
|
---|---|
resultsContainer |
gapi.cloudsearch.widget.resultscontainer.ResultsContainer 值不得為空值。 |
- 另請參閱
- ResultsContainer
- 傳回
-
non-null Builder
this
setSearchApplicationId
setSearchApplicationId(searchApplicationId) 會傳回 Builder
(選用) 設定在要求中使用的搜尋應用程式 ID。開頭必須為「searchapplications/」。
參數 |
|
---|---|
searchApplicationId |
字串 |
- 傳回
-
non-null Builder
this
setThrottleInterval
setThrottleInterval(throttleInterval) 會傳回 Builder
(選用) 觸發要求的節流間隔 (以毫秒為單位)。搜尋方塊每隔 throttleInterval 毫秒傳送一次要求。如果 throttleInternal 小於 200,搜尋方塊會忽略該值,改用 200 做為間隔。
參數 |
|
---|---|
throttleInterval |
數字 |
- 傳回
-
non-null Builder
this