Backbone.js 重置主干中的收集
块1: initialize方法按预期正常工作,但当从块3调用“SelectIndustry”时,*this.query未定义* })) 块2: 这在页面加载时与其他主干函数一起调用Backbone.js 重置主干中的收集,backbone.js,Backbone.js,块1: initialize方法按预期正常工作,但当从块3调用“SelectIndustry”时,*this.query未定义* })) 块2: 这在页面加载时与其他主干函数一起调用 vent = _.extend({}, Backbone.Events); complienceList = new ComplienceCollection(); 块3: 从普通javascript文件调用 vent.trigger("onSelectIndustry",indutryt
vent = _.extend({}, Backbone.Events);
complienceList = new ComplienceCollection();
块3:
从普通javascript文件调用
vent.trigger("onSelectIndustry",indutrytype);
它看起来像javascript中的
this
的具体用法,根据调用方法的不同而有所不同。而不是
vent.bind("onSelectIndustry", this.SelectIndustry);
试试这个:
var self = this;
vent.bind("onSelectIndustry", function( oid ){ self.SelectIndustry( oid ) });
如果这样做有效,您可以通过类似于
$.proxy
或类似的方式来美化您的通话。尝试将此绑定到SelectIndustry。\uz。bindAll(这是“SelectIndustry”);或者vent.bind(“onSelectIndustry”,this.SelectIndustry,this)
如果您想避免不必要的函数包装器。
var self = this;
vent.bind("onSelectIndustry", function( oid ){ self.SelectIndustry( oid ) });