【问题标题】:Twitter typeahead.js save remote response into localStorageTwitter typeahead.js 将远程响应保存到 localStorage
【发布时间】:2013-08-30 19:45:57
【问题描述】:

我想知道是否可以使用 typeahead.js 将远程查询保存到 localSorage。

我使用 Bootstrap 2 typeahead 进行了此操作,但无法使用 typeahead.js。

示例: 在输入中输入:“Ger”

脚本检查 localStorage 中是否有内容。

  • 如果 NOT 从远程 url 获取响应并将其保存在 localStorage 中。
  • 如果 YES 从 localStorage 获取数据并打印。

我正在使用typeahead.js 0.9.3

【问题讨论】:

    标签: twitter-bootstrap twitter-bootstrap-3 typeahead.js


    【解决方案1】:

    对于prefetch 数据,这样的可能性。来自文档:

    在初始化时获取和处理预取数据。如果 浏览器支持localStorage,处理后的数据会缓存在那里 以防止在后续页面加载时出现额外的网络请求。

    ...prefetch 对象中的相关选项是:

    ttl – 预取数据应缓存在 localStorage 中的时间(以毫秒为单位)。 > 默认为 86400000(1 天)。

    请看这里:https://github.com/twitter/typeahead.js#prefetch

    从来源来看,进一步看来:

    1. PersistentStorage 确实只适用于prefetch,并且要使用数据集必须使用name 进行初始化。

    2. 传输层中有一个额外的内存中请求/响应缓存。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-18
      相关资源
      最近更新 更多