我有一个 Backbone 观点。我想在搜索文本字段中发生的每次更改时从服务器设置 Bootstrap 提前输入的数据源。我怎样才能做到这一点??这是我的搜索 View
window.SearchByChoiceView = Backbone.View.extend({
initialize: function () {
this.model = new SearchByChoiceModel();
this.render();
},
render: function () {
$(this.el).empty().html(this.template(this.model.toJSON()));
return this;
},
});
window.SearchByChoiceModel = Backbone.Model.extend({
initialize: function () {
},
defaults: {
id: 1,
SearchKeyword: "",
"tags": new Array()
}
});
这是我的搜索字段:
<input type="text" required placeholder="search" class="input-span3" id="SearchKeyword" title= "Search Keyword" name="SearchKeyword" value="<%= SearchKeyword %>" style="margin: 0 auto;" data-provide="typeahead" data-items="4">
请大家帮忙。我是一个有骨气的初学者。也许这很容易,但对我来说很难处理。我已经尝试了很多。
最佳答案
我相信你能做到:
$( '.typeahead' ).typeahead( {
source : typeAhead.people.pluck( 'name' )
} );
});
其中“typeAhead.people”是您的集合实例。对于你的情况
myApp.myCollection.pluck( 'SearchKeyword' )
JSBin:
关于backbone.js - 如何在我的主干 View 中绑定(bind) Bootstrap 提前输入的数据源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13974142/