自定义组件ExtJS,而不是工作setValue

Custom component ExtJS, not work setValue

本文关键字:工作 setValue 组件 ExtJS 自定义      更新时间:2023-09-26

任何人,请帮助我为extjs 4.2 创建组件

Ext.define('mycomponent', {
    extend:'Ext.form.field.Display',
    alias: 'widget.mycomponent',
    initComponent: function() {
        this.setValue("some value") // not setup
        this.callParent(arguments);
        console.log(this)
    },
})

我试试

Ext.getCmp(this.id).setValue("some")

但html对象不存在,e.t.c.之前的事件未运行。我如何设定价值?

这是一个完整的工作示例,用4.2.1进行了测试。

Ext.define('Foo', {
    extend:'Ext.form.field.Display',
    alias: 'widget.mycomponent',
    initComponent: function() {
        this.setValue("some value") // not setup
        this.callParent(arguments);
    }
})
Ext.onReady(function() {
    new Foo({
        renderTo: document.body
    })
}); 

您需要在构造函数中定义getValue()和setValue()方法才能工作。

getValue: function () {
        var me = this,
            value;
        return value;
    }
    setValue: function (value) {
        var me = this;
// Example only should't work as it is
        me.displayField.setValue(value);
    }