我有一个Backbone Collection,只要另一个Backbone Model(没有Collection的一部分)发生变化就需要获取.
当我这样写:
this.fModel = new FooModel();
this.bCollection = new BarCollection();
this.fModel.on("change", this.bCollection.fetch, this)
Run Code Online (Sandbox Code Playgroud)
触发更改事件时,我收到以下错误:
Uncaught TypeError: Object #<Object> has no method 'trigger'
Run Code Online (Sandbox Code Playgroud)
但是,当我简单地包装Collection的fetch调用时,它按预期工作:
this.fModel = new FooModel();
this.bCollection = new BarCollection();
this.testfunc = function(){
this.bCollection.fetch();
}
this.fModel.on("change", this.testfunc, this)
Run Code Online (Sandbox Code Playgroud)
为什么会这样?谢谢!