类:Builder

构造函数

构建器

新的 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() 会返回 SearchBox

返回

non-null SearchBox 

setAdapter

setAdapter(adapter) 会返回 Builder

强制要求。使用此适配器自定义用户的搜索体验。

参数

适配器

SearchBoxAdapter

您可以替换部分方法。

值不能为 null。

返回

non-null Builder

示例

const adapter = {
 interceptSuggestRequest: function(request) {
    // Change the request
  }
}

builder.setAdapter(adapter).build();

setAnchor

setAnchor(anchor) 会返回 Builder

强制要求。必须是可以包含子节点的有效 HTMLElement。 搜索叠加层的锚点。该叠加层将添加为锚点中的最后一个子项。叠加层的位置是锚点的底部。

参数

锚标记

HTMLElement

值不能为 null。

已弃用
改用“setAnchorElement”
返回

non-null Builder

setAnchorElement

setAnchorElement(anchorElement) 返回 Builder

强制要求。必须是可以包含子节点的有效 HTMLElement。 搜索叠加层的锚点。该叠加层将添加为锚点中的最后一个子项。叠加层的位置是锚点的底部。

参数

anchorElement

HTMLElement

值不能为 null。

返回

non-null Builder

setHints

setHints(hints) 返回构建器

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

参数

提示

字符串数组

值不能为 null。

返回

non-null Builder

setInput

setInput(input) 返回 Builder

强制要求。用户输入查询的 HTMLElement。 必须为 <input> 或 <textarea>

参数

输入

HTMLElement

值不能为 null。

已弃用
改用“setInputElement”
返回

non-null Builder

setInputElement

setInputElement(inputElement) 返回构建器

强制要求。用户输入查询的 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) 返回 Builder

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

参数

searchApplicationId

string

返回

non-null Builder

setThrottleInterval

setThrottleInterval(throttleInterval) 会返回 Builder

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

参数

throttleInterval

number

返回

non-null Builder