类:Builder

构造函数

构建器

新 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

您可以替换部分方法。

值不能为 null。

返回

non-null Builder 这个

示例

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

builder.setAdapter(adapter).build();

setAnchor

setAnchor(anchor) 返回构建器

必需。必须是有效 HTMLElement,可以包含子元素 节点。 搜索叠加层的锚点。叠加层已添加 作为锚点中的最后一个子元素。叠加层的位置是 底部对齐。

参数

anchor

HTMLElement

值不能为 null。

已弃用
改用“setAnchorElement”
返回

non-null Builder 这个

setAnchorElement

setAnchorElement(anchorElement) 返回构建器

必需。必须是有效 HTMLElement,可以包含子元素 节点。 搜索叠加层的锚点。叠加层已添加 作为锚点中的最后一个子元素。叠加层的位置是 底部对齐。

参数

anchorElement

HTMLElement

值不能为 null。

返回

non-null Builder 这个

setHints

setHints(hints) 会返回构建器

可选。输入为空时搜索框上的提示。 当输入为空时,系统会从数组中随机选择一个提示。

参数

提示

字符串数组

值不能为 null。

返回

non-null Builder 这个

setInput

setInput(input) 返回构建器

必需。用户输入查询的 HTMLElement。 必须是 <input>或 <textarea>

参数

输入

HTMLElement

值不能为 null。

已弃用
改用“setInputElement”
返回

non-null Builder 这个

setInputElement

setInputElement(inputElement) returns Builder

必需。用户输入查询的 HTMLElement。 必须是 <input>或 <textarea>

参数

inputElement

HTMLElement

值不能为 null。

返回

non-null Builder 这个

setResultsContainer

setResultsContainer(resultsContainer) 返回构建器

可选。用于显示搜索结果的容器。 如果设置了此字段,则结果会显示在搜索结果容器中。 如果未设置,结果会显示在 cloudsearch.google.com 中。

参数

resultsContainer

gapi.cloudsearch.widget.resultscontainer.ResultsContainer

值不能为 null。

另请参阅
ResultsContainer
返回

non-null Builder 这个

setSearchApplicationId

setSearchApplicationId(searchApplicationId) 返回构建器

可选。设置要用于请求的搜索应用 ID。必须 带有“searchapplications/”前缀。

参数

searchApplicationId

字符串

返回

non-null Builder 这个

setThrottleInterval

setThrottleInterval(throttleInterval) 会返回构建器

可选。触发请求时的节流间隔(以毫秒为单位)。 搜索框每 throttleInterval 发送一次请求的次数少于 1 次 毫秒。如果 throttleInternal 小于 200,则搜索框会忽略 值,并改用 200 作为间隔。

参数

throttleInterval

number

返回

non-null Builder 这个