0

このバックボーンスクリプトには、単一のビューとコントローラーとして機能するモデル、およびサーバーからデータがフェッチされるコレクションがありますurl: '/search/:term'

    var Items = Backbone.Collection.extend({
          initialize: function(terms){
            this.fetch();
        }
          url: 'search/:term'
    });

   var Controller = Backbone.Model.extend({
       defaults:{
        term: ""
     },
      initialize: function(opts){

        this.on('change:term', function(term){
            console.log(this.get("term"));
          // every time term changes i want to refresh the collection with the new data
          // so it will fetch data from url:'search/ + term'
        });

誰かがこれで私を助けてくれますか?}});

4

1 に答える 1

0

バックボーンコンテキストでは、ビューはコントローラーとして機能します(コントローラーフォームmvcを読み取ります)。あなたはこのようなことをしようとすることができますか?

YourView = Backbone.View.extend({
  events : { 
    'change #dom-id' : 'handleChange' //function to fire when you change the dom
  },
  initialize: function(){
    this.collection.bind("reset", updateView); //when collection is done, updateView fires
  }, 
  render: function(){
    //do your render logic here, use a template etc.. //initial rendering
  },
  handleChange : function(changeEvent){
    //get value from dom-element, tell the collection to 
    //fetch again with the new term
  },
  updateView : function(){
    //Code that fires when the collection is done fetching 
  }
});
于 2012-08-16T19:22:59.830 に答える