开发者

Custom Object Properties in ExtJs Component

How can I add custom properties into control objects in ExtJs.

For example :

var button = new Ext.Button({
    text:"something",
    id:"somethingId"
})

This control comes from server dynamically and I want to write my custom property as well like below :

var button = new Ext.Button({
    text:"something",
    id:"somethingId",
    customField : "I created this one"
})

and then I want to reach it like below :

alert(button.customField);

In my real case I am doing this type to create AsyncTreeNode at server and send them to client and append them via TreeLoader, and those nodes helps me show a picture when clicked so I want them to have a address field so I can get it in TreePanel click event which开发者_运维技巧 returns clicked node as well :

listeners:{
   click : function(clickedNode,eObj){
       alert(node.customFields);   
   }
}

I tried it but it said undefined. Normally since JavaScript is loose, I can easily modify objects but in this case it wouldn't work the way I expected.

Thanks in advance....


I've found the solution.

ExtJs is providing attributes property to get all the custom supplied attributes :

Attributes : Object The attributes supplied for the node. You can use this property to access any custom attributes you supplied.

So after I inject the custom property during initial Configuration I get them by using attributes :

listeners: {
            click: function(node) {
                $("#nodeId").val(node.id);
                if (node.isLeaf()) {
                    $("#galleryImage").attr("src", "../Galleries/" + node.attributes.image);
                }
            }
        }


Include in your class following code:

config : {
    renderTo: null,
},

constructor: function(config)
{
    this.initConfig(config);

    return this;
},

This way getter and setter, methods for every config property are automatically generated into the class' prototype during class creation if the class does not have these methods already defined. ... and you can access properties as you wished initially.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜