backbone.js - 如何在我的主干 View 中绑定(bind) Bootstrap 提前输入的数据源?

标签 backbone.js twitter-bootstrap bootstrap-typeahead

我有一个 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:

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

关于backbone.js - 如何在我的主干 View 中绑定(bind) Bootstrap 提前输入的数据源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13974142/

相关文章:

jquery - Bootstrap typeahead - 如何手动设置默认值

javascript - 预输入不更新字段

javascript - 如何从 fetch :success event? 中获取这个集合

javascript - 在遍历 Backbone Collection 时更新 DOM?

javascript - Jquery 文件上传和 Backbone 的上下文

javascript - Bootstrap 3 :navbar not working

jquery - twitter typeahead 使用预取内容强制选择

javascript - backbone.js - 随请求获取额外数据

javascript - Bootstrap 错误验证颜色未显示

html - 使用 Bootstrap 动态居中水平图像