【发布时间】:2012-08-16 19:08:23
【问题描述】:
我有这个主干脚本,它有一个视图和一个充当控制器的模型,以及一个从服务器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。在主干上下文中,视图充当控制器。
标签: javascript model-view-controller backbone.js