第1区: initialize方法按预期正常工作,但是当从 Block 3 * 调用“SelectIndustry”时,this.query未定义 *
ComplienceCollection = Backbone.Collection.extend({
model: Complience,
initialize: function () {
_.bindAll(this, 'selectFeaturesCallback');
vent.bind("onSelectIndustry", this.SelectIndustry);
if(industrylookup == null)
{
industrylookup = "http://hostname/ArcGIS/rest/services/sss/MapServer/2?f=json";
}
this.queryTask = new esri.tasks.QueryTask(industrylookup);
dojo.connect(this.queryTask, 'onComplete', this.selectFeaturesCallback);
this.query = new esri.tasks.Query();
this.query.returnGeometry = false;
this.query.where = '1=1';
this.query.outFields = ['*'];
this.queryTask.execute(this.query);
},
selectFeaturesCallback: function (featureSet) {
var item=_.pluck(featureSet.features, "attributes");
this.reset(item);
},
SelectIndustry: function (oid) {
this.query.where = '1=1';
this.queryTask.execute(this.query);
}
});
第2块: 这是在页面加载时使用其他主干函数调用的
vent = _.extend({}, Backbone.Events);
complienceList = new ComplienceCollection();
第3区: 从普通的javascript文件调用
vent.trigger("onSelectIndustry",indutrytype);
答案 0 :(得分:1)
看起来javascript中this
的具体情况可能因调用方法而异。而不是
vent.bind("onSelectIndustry", this.SelectIndustry);
试试这个:
var self = this;
vent.bind("onSelectIndustry", function( oid ){ self.SelectIndustry( oid ) });
如果这样可行,您可以通过$.proxy
或类似内容来美化您的通话。