嘗試是這樣的
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時,請使用
MixedCollection.replace
以新的令牌ID更新id
密鑰。
- 處理程序將觸發
replace
,並更新所有相關組件的偵聽器。