Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Backbone.js 如何在主干视图中绑定bootstrap typeahead的数据源?_Backbone.js_Twitter Bootstrap_Bootstrap Typeahead - Fatal编程技术网

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: