【问题标题】:How can I bind datasourse of bootstrap typeahead in my backbone view?如何在我的主干视图中绑定 bootstrap typeahead 的数据源?
【发布时间】:2012-12-20 14:19:39
【问题描述】:

我有一个主干视图。我想在搜索文本字段中发生的每次更改中从服务器设置引导输入的数据源。我怎样才能做到这一点??这是我的搜索视图

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">

请任何人帮助。我是一个有骨气的初学者。也许这很容易,但对我来说很难处理。我已经尝试了很多。

【问题讨论】:

    标签: backbone.js twitter-bootstrap bootstrap-typeahead


    【解决方案1】:

    我相信你可以做到:

    $( '.typeahead' ).typeahead( {
        source : typeAhead.people.pluck( 'name' )
      } );
    });
    

    其中“typeAhead.people”是您的集合实例。你的情况

    myApp.myCollection.pluck( 'SearchKeyword' )
    

    JSBin:

    http://jsbin.com/upigej/1/edit

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-03
      相关资源
      最近更新 更多