我在同一 Backbone View 中的两个位置使用 defer()
来运行两个不同的函数。但是,两者都会导致以下错误:
两个函数调用位于渲染函数内:
loadReferralCollection: function(collection) {
console.log("hello")
},
loadRemixedCollection: function(collection) {
console.log("hello")
},
render: function() {
var self = this;
if ( this.options.params !== undefined && this.options.params.referral !== undefined ){
_( self.loadReferralCollection(self.model) ).defer();
} else if ( this.options.params !== undefined && this.options.params.remix !== undefined ) {
_( self.loadRemixedCollection(self.model) ).defer();
}
}
完整错误:
Uncaught TypeError: Cannot call method 'apply' of undefined underscore.js?body=1:621
(anonymous function)
最佳答案
defer() 想要推迟函数调用。所以你必须传递一个函数:
或者:
_( function() { self.loadRemixedCollection(self.model); } ).defer();
或者
_( self.loadRemixedCollection ).defer(self.model);
好吧,或者
_.defer( function() { self.loadRemixedCollection(self.model); } )
_.defer( self.loadRemixedCollection, self.model )
关于javascript - Backbone 中 Underscore 的 .defer() 导致错误 : Cannot call method 'apply' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18771298/