我有這個骨幹腳本,它有一個單一的視圖和作爲控制器的模型,以及從服務器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'
});
有人可以幫我這個謝謝。 } });
你能證明你試圖達到什麼嗎?如果你試圖聽一些dom事件,你應該使用Backbone.View。在主幹上下文中,View充當Controller。 – 2012-08-16 19:14:10