EXTJS7 eventedConfig用法

  1. 使用eventedConfig的類需繼承’Ext.Evented’
  2. eventedConfig自動併入到config中
// Evented.js源碼
Ext.define('Ext.Evented', {
onClassExtended: function(cls, data) {
        if (config) {
            Ext.applyIf(config, eventedConfig);
        }
        else {
            cls.addConfig(eventedConfig);
        }
    }
});
  1. 通過set方法修改值的時候會觸發before[configName]change和[configName]change事件
  2. 在before[configName]change事件函數中返回false可以阻止setter執行
Ext.define('MyApp.util.Test', {
    extend: 'Ext.Evented',

    eventedConfig: {
        foo: null
    }
});

var test = Ext.create('MyApp.util.Test', {
    listeners: {
        beforefoochange: function (instance, newValue, oldValue) {
            return newValue !== 'bar';
        },
        foochange: function (instance, newValue, oldValue) {
           console.log('foo changed to:', newValue);
        }
    }
});

test.setFoo('bar');
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章