尝试这样的事情
Ext.onReady(function() {
var token = new Ext.util.MixedCollection();
token.add('id', 'THE_TOKEN_ID');
Ext.ComponentMgr.register('token', token);
});
将事件侦听器附加到MixedCollection
更新任何关心令牌的组件。
// now you need all the event listeners
var token = Ext.getCmp('token');
var component = Ext.getCmp('some_component_that_needs_ajax');
token.on('replace', function(key, value, original) {
if(key == 'id') {
component.params.token_id = value; // update the new value
}
});
每当令牌需要更新时,请执行
var token = Ext.getCmp('token');
token.replace('id', 'THE_NEW_TOKEN_ID');
这里发生的事情是:
- 您创建一个
MixedCollection
以包含有关您的令牌的信息。
- 当有新令牌时需要更新的任何组件都应在
replace
令牌侦听器的处理程序中更新MixedCollection
。
- 当您获得新的令牌 ID 时,使用新的令牌 ID
MixedCollection.replace
更新id
密钥。
- 处理程序将
replace
触发,并且更新所有依赖组件的侦听器。