0

上有 2 个按钮Ext.WIndow。当我单击按钮 1 时,将执行以下代码。

当我点击按钮 2 时,第二组代码被执行。这两个按钮都将从Store

问题;

当我单击第一个按钮时,console.log会打印以下语句(这是我预期的方式)

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'));
}
4

1 回答 1

1

我认为您的大部分问题仅仅是因为您load多次订阅该事件。基本上,当您执行 Button2 代码时 - store 将有两个处理程序load,它们将同时运行。

Usually when you subscribe to the load event you want to add { single: true } option, so the handler will get called once and will be removed from the store.

store.on('load', 
   function() {...},  
   scope /* this or something like it... */,
   { single: true }
);
于 2012-08-01T12:05:20.497 回答