Backbone.js 如何在主干视图中绑定bootstrap typeahead的数据源?
我有主心骨的观点。我想在搜索文本字段中发生的每次更改中,从服务器预先设置引导类型的数据源。我该怎么做??这是我的搜索视图Backbone.js 如何在主干视图中绑定bootstrap typeahead的数据源?,backbone.js,twitter-bootstrap,bootstrap-typeahead,Backbone.js,Twitter Bootstrap,Bootstrap Typeahead,我有主心骨的观点。我想在搜索文本字段中发生的每次更改中,从服务器预先设置引导类型的数据源。我该怎么做??这是我的搜索视图 window.SearchByChoiceView = Backbone.View.extend({ initialize: function () { this.model = new SearchByChoiceModel(); this.render(); }, render: function () { $(this.el).empty()
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: