开发者

how to get args to constructor at extjs?

I have a some class

AddOrgWindowUI = Ext.extend(Ext.Window, {
title: 'form',
width: 400,
height: 198,
layout: 'form',
padding: 5,
initComponent: function() {
    this.items = [
        {
            xtype: 'textfield',
            fieldLabel: 'parapapa',
            anchor: '95%',
            value: m,
            emptyText: 'perapapa'
        }
    ];
    AddOrgWindowUI.superclass.initComponent.call(this);
}});

when I create an object var AddOrgWindowForm = new AddOrgWindowUI('aaa'); I want to get arg ('aaa') to my new form value (value m). How get it? Im trying initComponen开发者_C百科t: function(m) { and thats not working.


The initComponent function is called internally on one of the base classes of Ext.Window. You shouldn't try to call it directly. That is why it won't handle your own parameters.

So I recommend you to use the standard form parameters when extending ExtJS classes.

It is as simple as initializing the object with the property or methods you want to override (or insert in case the property is not in there already). And then just using the this keyword to access them.

This is possible because for every Ext.Component and its subclasses, the first parameter passed to the constructor should be an object, and every member in that object will be copied to the new object constructed. And most ExtJS classes extend directly or indirectly from Ext.Component, and you are extending from Ext.Window which extends from Ext.Component too.

Here you have your example fixed:

var AddOrgWindowUI = Ext.extend(Ext.Window, {
    title: 'form',
    width: 400,
    height: 198,
    layout: 'form',
    padding: 5,

    initComponent: function() {
        this.items = [
            {
                xtype: 'textfield',
                fieldLabel: 'parapapa',
                anchor: '95%',
                value: this.initialValue,
                emptyText: 'perapapa'
            }
        ];
        AddOrgWindowUI.superclass.initComponent.call(this);
    }
});

function test() {
    var AddOrgWindowForm = new AddOrgWindowUI({initialValue:'aaa'});
    AddOrgWindowForm.show();
}


pass m as an arg of initComponent:

edit:

AddOrgWindowUI = function(input) {
    var m = input;
    return Ext.extend(Ext.Window, {
        title: 'form',
        width: 400,
        height: 198,
        layout: 'form',
        padding: 5,
        initComponent: function() {
            this.items = [
        {
            xtype: 'textfield',
            fieldLabel: 'parapapa',
            anchor: '95%',
            value: m,
            emptyText: 'perapapa'
        }
    ];
            AddOrgWindowUI.superclass.initComponent.call(this);
        }
    });
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜