2014-02-11 30 views
0

塊1:如預期,但是當 「SelectIndustry」 是從稱爲第3座 * this.query未定義 initialize方法工作得很好 *復位收集

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

嘗試將其綁定到SelectIndustry。 _.bindAll(this,'SelectIndustry'); – Konza

回答

1

它看起來像特定在JavaScript中的this,根據調用方法可能會有所不同。取而代之的

vent.bind("onSelectIndustry", this.SelectIndustry); 

試試這個:

var self = this; 
vent.bind("onSelectIndustry", function(oid){ self.SelectIndustry(oid) }); 

如果這個工程,你可以通過類似$.proxy或類似美化你的電話。

+1

或'vent.bind(「onSelectIndustry」,this.SelectIndustry,this)'如果你想避免不必要的函數包裝。 –