2014-02-11 3 views
0

블록 1 : 초기화 방법은 예상되지만 "SelectIndustry가"this.query 정의되지 않은 블록 (3) * 로부터 호출 될 때 잘 작동 *리셋 컬렉션

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라고 : 일반에서 호출 자바 스크립트 파일 그것은 특정 모양

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)'를 참조하십시오. –