typeahead.js预取不起作用 [英] typeahead.js prefetch doesn't work
问题描述
我无法在typeahead.js中使用预取功能,但是它与本地数据配合使用还是不错的.我首先尝试链接到返回json对象或列表的servlet,但过了一会儿我放弃了,开始检查提供的示例.因此,他们的示例链接到如下页面: http://twitter.github.io/typeahead.js/data/countries.json 但是,即使我执行与脚本完全相同的操作,将脚本链接到该页面时,脚本也无法正常工作.我尝试将该文件复制到本地工作区,然后再链接到那里都无济于事.为了检查它是否在进行任何调用,我每次获得get请求时都会使servlet崩溃,并且确保运行我的自动完成示例页面时它崩溃了,所以这不是缓存问题.我尝试将jquery降级到1.9.1,但是那也不起作用(当前使用1.10).我尝试使用不同版本的typeahead.js.我尝试使用Internet Explorer以及谷歌浏览器查看错误是否存在.
I can't get the prefetch function in typeahead.js to work, it works just fine with the local data though. I first tried linking to a servlet returning json objects or lists, but after a while I gave up on that and started checking the provided examples. So their examples links to pages that look like this: http://twitter.github.io/typeahead.js/data/countries.json However, my script doesn't even work when I link it to that page even if I do exactly the same thing as they do. I tried copying that file over to my local workspace and linking to it there to no avail. To check if it even were making any calls I made my servlet crash every time it got a get request, and sure enough it crashed when I ran my autocomplete example page so it isn't a cache problem. I tried downgrading jquery to 1.9.1, but that didn't work either(currently using 1.10). I tried using different versions of typeahead.js. I tried using internet explorer as well as google chrome to see if the error was there.
由于我已经穷尽了所有我能想到的错误来源,因此我必须缺少一些重要的东西.其他人似乎对此没有任何问题.
There must be something vital that I am missing, as I have exhausted every source of errors I could think of. Others don't seem to have any problems getting this to work.
这是我使用的代码:
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Demo</title>
<link rel="stylesheet" type="text/css" href="typeahead.js-bootstrap.css">
</head>
<body>
<script src="jquery.js"></script>
<script src="typeahead.js"></script>
<input type="text" class="typeahead" placeholder="test" />
<script>
$(document).ready(function() {$('.typeahead').typeahead({
name: "Auto" ,
ttl_ms: 10000,
prefetch: 'http://twitter.github.io/typeahead.js/data/countries.json',
//local: ['abc', 'acd', 'ade', 'bcd]
});});
</script>
</body>
</html>
推荐答案
似乎该问题与浏览器存储中数据的缓存有关.
It seems the issue is related to caching of the data in the browser storage.
- 您可以清理浏览器存储(而不是浏览器缓存).
- 您可以将typeahead配置中的数据集
name
更改为另一个. -
您可以降低
prefetch
中的ttl
.当然,您可以稍后增加ttl
.见下文:
- You can clean your browser storage (not the browser cache).
- You can change the dataset
name
in typeahead config to another one. You can lower the
ttl
inprefetch
. You can increase thettl
later, of course. See below:
prefetch: {
url: 'http://twitter.github.io/typeahead.js/data/countries.json',
ttl: 1 // in milliseconds
},
如果您在此处浏览代码,将会更加清楚: http://goo.gl/TN3Gv
It will be more clear if you browse the code here: http://goo.gl/TN3Gv
这篇关于typeahead.js预取不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!