2

私はバックボーン ビューを持っています。検索テキストフィールドで変更が発生するたびに、サーバーからブートストラップタイプアヘッドのデータソースを設定したい。これどうやってするの??これは私の検索ビューです

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

誰か助けてください。背骨のあるビギナーです。簡単かもしれませんが、私にとっては扱いが非常に難しいです。私はたくさん試しました。

4

1 に答える 1

2

私はあなたがこれを行うことができると信じています:

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

「typeAhead.people」はコレクション インスタンスです。あなたの場合

myApp.myCollection.pluck( 'SearchKeyword' )

JSビン:

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

于 2012-12-20T16:15:31.157 に答える