我尝试使用外部Json作为自动完成Jquery UI插件的源代码:http://jqueryui.com/autocomplete/
我不理解json的好方法和好格式。在我示例中,我的json中包含:"tag1“、"tag2”、"tag3“
自动补全似乎是可行的,但是如果以输入"a“开头,自动补全将建议json中的所有标签。看起来autocomplete并没有过滤json的内容,总是在json中显示整个标签。因此,我不明白如何拥有正常的行为:例如,当我键入"t“时,自动补全功能只建议我输入"tag1”。
我的页面在这里:http://tcdemo.fr/temp/test.html
Json在这里:http://tcdemo.fr/temp/search.json
非常感谢
发布于 2014-09-24 00:43:53
查看您的代码,您可以为解决方案做三件事:
.tagit()绑定外部加载json并将json结果传递给availableTags属性。默认情况下会处理过滤。$(“#mytag”).tagit({ availableTags: jsonResult,// search.json is loaded into jsonResult show_tag_url:"/tags/",singleField: true,singleFieldNode:$('#submit_tag_names') });
成功:函数(选项){ var filter = search.term.toLowerCase();var filteredChoices =$.grep(选项,函数(元素){ //仅匹配以搜索词开头的自动完成选项。showChoices(this._subtractArray(filteredChoices,(element.toLowerCase().indexOf(filter) === 0);});return this.assignedTags();}
希望这能有所帮助
https://stackoverflow.com/questions/25997244
复制相似问题