類別:建構工具

建構函式

Builder

新品 建構工具()

範例

// Builds a search box.
function onload() {
  gapi.client.init({
    &#x27;apiKey&#x27;: &#x27;<your api key>&#x27;,
    &#x27;clientId&#x27;: &#x27;<your client id>&#x27;,
    // Add additional scopes if needed
    &#x27;scope&#x27;: &#x27;https://www.googleapis.com/auth/cloud_search.query',
    &#x27;hosted_domain&#x27;: &#x27;<your G Suite domain>&#x27;,
  });

  const searchBox &#x3D; new gapi.cloudsearch.widget.searchbox.Builder()
    .setInput(document.getElementById(&#x27;input&#x27;))
    .setAnchor(document.getElementById(&#x27;input&#x27;).parentElement)
    .build();
}
gapi.load(&#x27;client:cloudsearch-widget&#x27;, onload);

方法

build

build() returns SearchBox

傳回

non-null SearchBox 

setAdapter

setAdapter(adapter) 傳回建構工具

必填。透過這個轉接器自訂使用者的搜尋體驗。

參數

轉接器

SearchBoxAdapter

您可以覆寫部分方法。

值不得為空值。

傳回

non-null Builder

範例

const adapter &#x3D; {
 interceptSuggestRequest: function(request) {
    // Change the request
  }
}

builder.setAdapter(adapter).build();

setAnchor

setAnchor(Anchor) 傳回 Builder

必填。必須是可包含子項的有效 HTMLElement 節點。 搜尋疊加層的錨點。已新增疊加層 做為錨點中的最後一個子項疊加畫面的位置是 錨定標記底部。

參數

anchor

HTMLElement

值不得為空值。

已淘汰
改用「setAnchorElement」
傳回

non-null Builder

setAnchorElement

setAnchorElement(AnchorElement) 傳回建構工具

必填。必須是可包含子項的有效 HTMLElement 節點。 搜尋疊加層的錨點。已新增疊加層 做為錨點中的最後一個子項疊加畫面的位置是 錨定標記底部。

參數

anchorElement

HTMLElement

值不得為空值。

傳回

non-null Builder

setHints

setHints(提示) 傳回建構工具

(選用) 輸入內容為空白時,搜尋框中顯示的提示。 如果輸入為空白,系統會從陣列中隨機挑選提示。

參數

提示

字串陣列

值不得為空值。

傳回

non-null Builder

setInput

setInput(input) 傳回建構工具

必填。使用者輸入查詢的 HTML 元素。 必須為 <input>或<textarea>

參數

輸入

HTMLElement

值不得為空值。

已淘汰
改用「setInputElement」
傳回

non-null Builder

setInputElement

setInputElement(inputElement) returns Builder

必填。使用者輸入查詢的 HTML 元素。 必須為 <input>或<textarea>

參數

inputElement

HTMLElement

值不得為空值。

傳回

non-null Builder

setResultsContainer

setResultsContainer(resultsContainer) 傳回 Builder

(選用) 用來顯示搜尋結果的容器。 如有設定,則結果會顯示在搜尋結果容器中。 如未設定,結果會顯示在 cloudsearch.google.com 中。

參數

resultsContainer

gapi.cloudsearch.widget.resultscontainer.ResultsContainer

值不得為空值。

另請參閱
ResultsContainer
傳回

non-null Builder

setSearchApplicationId

setSearchApplicationId(searchApplicationId) 傳回建構工具

(選用) 設定用於要求的搜尋應用程式 ID。必選 前置字串為「searchapplications/」。

參數

searchApplicationId

字串

傳回

non-null Builder

setThrottleInterval

setThrottleInterval(throttleInterval) 建構工具

(選用) 觸發要求時的節流間隔時間 (以毫秒為單位)。 搜尋框每 throttleInterval 傳送的要求不到一個 毫秒。如果 throttleInternal 小於 200,搜尋框會忽略 並改用 200 做為間隔

參數

throttleInterval

數字

傳回

non-null Builder