2012-08-01 2 views
0

Ext.WIndow에는 2 개의 버튼이 있습니다. Button 1을 클릭하면 다음 코드가 실행됩니다.잘못된 저장소로드 중

버튼 2를 클릭하면 두 번째 코드 세트가 실행됩니다. 이 두 버튼은 모두에서로드됩니다 Store

문제가 있습니다.

내가 1 버튼을 클릭

, 다음 console.log 문은 내가 2 버튼 클릭이 후

console.log ('win 1'); 
console.log('Came win 1'); 

(내가 예상하는 방식이다) 인쇄됩니다, 나는 잘못된 console.log가 표시됩니다 얻을 .

console.log ('win 2'); 
console.log('Came win 1'); // Which is coming from the 1st Buttons Load function. 

버튼 1

 var personCus= Ext.getStore('Person'); 
     var record = personCus.getAt(0); 
    console.log ('win 1'); 
    personCus.on('load', function() { 
console.log('Came win 1'); 
     var label= Ext.ComponentQuery.query('#win1> #labido')[0]; 
     label.setText(record1.get('id')); 
} 

버튼 2

 var personCus= Ext.getStore('Person'); 
     var record = personCus.getAt(0); 
    console.log ('win 2'); 
    personCus.on('load', function() { 
console.log('Came win 3'); 
     var label= Ext.ComponentQuery.query('#win2> #labid1')[0]; 
     label.setText(record1.get('id')); 
} 

답변

1

난 당신이 load 이벤트 여러 번에 가입하고 있기 때문에 문제의 대부분은 단순히 생각합니다. 기본적으로 Button2 코드를 실행할 때 - 상점에는 load에 대한 두 개의 핸들러가 있으며 둘 다 실행됩니다.

보통 load 이벤트에 가입하면 { single: true } 옵션을 추가해야하므로 처리기가 한 번 호출되어 상점에서 제거됩니다.

store.on('load', 
    function() {...}, 
    scope /* this or something like it... */, 
    { single: true } 
); 
관련 문제