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

时间:2013-08-05 08:55:44

标签: javascript extjs4

任何人,请帮我创建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.没跑我怎么能设定价值?

2 个答案:

答案 0 :(得分:0)

这是一个完整的工作示例,使用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
    })

}); 

答案 1 :(得分:0)

您需要在构造函数中定义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);
    }