Extjs合并对象 [英] Extjs merge objects

查看:75
本文介绍了Extjs合并对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有一个超级类,它定义了一个这样的对象:

  Ext.define('superclass' ,{
myObject:{
prop1:true,
prop2:200,
..
}

和继承上述超类的子类,声明同一个对象:

  Ext.define('childclass',{
extends:'superclass',

myObject:{
prop3:false,
prop4:false ,
..
}

问题在于,myObject在子类只有prop3和prop4属性。



我需要myObject ib子类具有所有prop1,prop2,prop3和prop4属性。



我如何做到这一点?

解决方案

扩展构造函数中的对象(或在initComponent如果你扩展Ext.Component):

  Ext $ {
extends:'superclass',

构造函数:function(){
this.myObject = Ext.apply({},this.myObject ,{
prop3:false,
prop4:false
});
this.callParent(arguments);
}
});

Demo


I have a super class in my application, that defines an object like this:

Ext.define('superclass', {
    myObject: {
        prop1: true,
        prop2: 200,
        ..
    }

and a child class that inherited the superclass above, that declares the same object:

Ext.define('childclass', {
    extend: 'superclass',

    myObject: {
        prop3: false,
        prop4: false,
        ..
    }

The problem is with that, the myObject in the child class has only the prop3 and prop4 properties.

I need that myObject ib child class has all prop1, prop2, prop3 and prop4 properties.

How can I do this ?

解决方案

Extend the object in the constructor (or in initComponent if you extend Ext.Component):

Ext.define('childclass', {
    extend: 'superclass',

    constructor: function() {
        this.myObject = Ext.apply({}, this.myObject, {
            prop3: false,
            prop4: false
        });
        this.callParent(arguments);
    }
});

Demo.

这篇关于Extjs合并对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆