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');
原创文章 68 获赞 61 访问量 2931

猜你喜欢

转载自blog.csdn.net/zhoudingding/article/details/105572188