我试着传递一些参数来查看构造函数。传递参数来查看
我以这种方式创建我的对象:new HeadCell({isSortable: true, parent: this});
所以在HeadCell初始化:
initialize: function(options){
console.log("HeadCell initialized");
console.log(options);
console.log(options.isSortable);
}
控制台输出为:
HeadCell initialized
Object {isSortable: true, parent: r}Uncaught TypeError: Cannot read property 'isSortable' of undefined
任何想法?
更新1
林尝试运行在拨弄一个小测试,结果是一样的。
http://jsfiddle.net/ramiromd90/hHFP3/
更新2
我尝试拨弄你的例子,和正常工作!但是,在我的代码不起作用。
在这里与我的实际代码一个小例子小提琴:
http://jsfiddle.net/ramiromd90/XCK47/
更新3
感谢所有的答复,问题是,我不传递回路参数(见小提琴)。传递参数的方法我们说的是正确的!由于
工作正常(http://jsfiddle.net/ambiguous/3HTq2/),你能提供你的问题的演示? –
@ muistooshort我用一个小提琴示例更新线程。 – ramiromd
你有'initialize:function(){'在你的小提琴中,但'initialize:function(options){'在你的问题中,后者工作正常(http://jsfiddle.net/ambiguous/bcU57/)。视图不会自动设置'this.options',它在版本1.1中被删除了:http://backbonejs.org/#changelog –