[英]How to read json data in typeahead.js?
我想读取JSON文件中的数据,然后将其与typeahead.js结合使用,这是一个链接
如果有人写下任何单词,例如EnglishWords [Best],它将显示他/她列出所有以best或like best开头的单词,然后选择该单词,然后显示该单词的描述,但我不知道,因为我是新手在JavaScript和JSON非常感谢:)
这是我的json数据文件的示例
var Words = [
{"EnglishWords":"Best","Description":"an expression of good some this"},
{"EnglishWords":"Best wishes","Description":"an expression of hope"},
{"EnglishWords":"Application","Description":"Computing a program or piece of software"},
-
-
-
-
-
-
];
看来您有两件事正在发生。 一种是自动完成功能,另一种是单词/短语定义?
typeahead.js
只会解决第一部分,但似乎很容易。 改编自github页面的示例,您将需要以下内容:
$('input.englishwords').typeahead({
name: 'words',
local: ['application', 'best', 'best wishes']
});
编辑:
您必须将JSON对象解析为数组或typeahead
输入的对象。 就像是:
var typeList = [];
for (var i = 0; i < Words.length; i++) {
typeList.push(Words[i].EnglishWords);
}
then:
$('input.englishwords').typeahead({
name: 'words',
local: typeList
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.