如何使用此示例响应json?
使用typeahead.js"data": {"id":"3","title":"Activities","slug":"","code":"","published":"0"},{"id":"2","title":"Domestic","slug":"","code":"","published":"0"},{"id":"1","title":"International","slug":"","code":"","published":"0"]
这是我与backbone.js集成的代码。此代码在引导程序2之前有效,但是当我将版本更新为引导程序3时,我需要修改此代码并为typehead.js添加单独的js,此代码不再起作用。有人可以帮我解决这个问题或建议更好的结果
var TypeAheadCollection = Backbone.Collecti.on.extend({model: Options});
$('.typeahead').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'title',
displayKey: 'title',
// source: substringMatcher(states)
source: function (query, process) {
queryAttributes = {};
queryAttributes['searchVal'] = query;
var list = [];
$.ajax({
url: that.collection.paginator_core.url,
data: queryAttributes,
dataType: 'json',
success: function (response) {
typeAheadCollection = new TypeAheadCollection(response.data);
console.log(typeAheadCollection.pluck('title'));
return process(typeAheadCollection.pluck('title'));
}
});
}
});
我把console.log用来检查显示数据。当你输入一个单词" a"在输入表格上有一个结果记录["活动","国际"]并且有一个下拉菜单,但显示的单词在两个单词上都是两个未定义的。我期待活动和国际。我怀疑问题是在" process()"
内答案 0 :(得分:0)
显示键采用您想要显示的对象中的项目名称。此时它被设置为显示不存在的“值”。