无法通过带有预取功能的猎犬使Twitter预先输入0.10(Not able to make Twitter typeahead 0.10 with bloodhound with prefetch

编程入门 行业动态 更新时间:2024-10-14 12:21:33
无法通过带有预取功能的猎犬使Twitter预先输入0.10(Not able to make Twitter typeahead 0.10 with bloodhound with prefetch to work)

我已经多次尝试使typeahead.js 0.10工作,只能使它与本地数据集一起使用。

使用预取或远程选项时,即使按照示例页面,它也不起作用。 要么我用错误的语法格式化json文件和/或搞乱了bloodhound选项。

老实说,“datumTokenizer:function(d){return Bloodhound.tokenizers.whitespace(d.value);},”实际上做了什么? 什么意思是空白......

好吧,我离开这里是我当前的例子,期望有人可以帮助我理解如何使用它。

如果可能的话,请你使用过滤器选项添加一个Bloodhound示例,以及正在使用的json文件示例。

JSON文件

[ { "year": "1961", "value": "Test Side Story", "tokens": [ "West", "Side", "Story" ] }, { "year": "1962", "value": "Tawrence of Arabia", "tokens": [ "Lawrence", "of", "Arabia" ] }, { "year": "1963", "value": "Tom Jones", "tokens": [ "Tom", "Jones" ] }, { "year": "2012", "value": "Argo", "tokens": [ "Argo" ] }

]

Typeahead 0.10脚本

<script> var films = new Bloodhound({ datumTokenizer: function(d) { return Bloodhound.tokenizers.whitespace(d.value); }, queryTokenizer: Bloodhound.tokenizers.whitespace, prefetch: 'http://localhost/dh/js/films.json' }); films.initialize(); $('#cenas0').typeahead(null, { displayKey: 'value', source: films.ttAdapter(), templates: { suggestion: Handlebars.compile( '<p><strong>{{value}}</strong> – {{year}}</p>' ) } }); </script>

HTML代码(带有一些脚本声明)

<script type="text/javascript" src="http://localhost/dh/js/jquery-1.9.1.js"></script> <script type="text/javascript" src="http://localhost/dh/js/typeahead.bundle.js"></script> <input id="cenas0" class="typeahead" placeholder="cenas0"></input>

I've already made several attempts to make the typeahead.js 0.10 to work and only can make it work with the local dataset.

When using prefetch or remote option, even following the examples page, it doesn't work. Either I am formatting the json file with the wrong syntax and/or messing up with the bloodhound options.

Honestly, what does the "datumTokenizer: function(d) { return Bloodhound.tokenizers.whitespace(d.value); }," actually do? what does it mean the whitespace...

Well, I leave here my current example with expectations that somebody can help me understand how to use this.

Can you please, if possible, add an example with Bloodhound using the filter option, along with the json file example being used.

JSON file

[ { "year": "1961", "value": "Test Side Story", "tokens": [ "West", "Side", "Story" ] }, { "year": "1962", "value": "Tawrence of Arabia", "tokens": [ "Lawrence", "of", "Arabia" ] }, { "year": "1963", "value": "Tom Jones", "tokens": [ "Tom", "Jones" ] }, { "year": "2012", "value": "Argo", "tokens": [ "Argo" ] }

]

Typeahead 0.10 script

<script> var films = new Bloodhound({ datumTokenizer: function(d) { return Bloodhound.tokenizers.whitespace(d.value); }, queryTokenizer: Bloodhound.tokenizers.whitespace, prefetch: 'http://localhost/dh/js/films.json' }); films.initialize(); $('#cenas0').typeahead(null, { displayKey: 'value', source: films.ttAdapter(), templates: { suggestion: Handlebars.compile( '<p><strong>{{value}}</strong> – {{year}}</p>' ) } }); </script>

HTML code (with some script declarations)

<script type="text/javascript" src="http://localhost/dh/js/jquery-1.9.1.js"></script> <script type="text/javascript" src="http://localhost/dh/js/typeahead.bundle.js"></script> <input id="cenas0" class="typeahead" placeholder="cenas0"></input>

更多推荐

本文发布于:2023-07-15 17:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1116657.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:猎犬   功能   Twitter   work   prefetch

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!