Extjs 合并对象 [英] Extjs merge objects

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

问题描述

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

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,
        ..
    }

问题在于,子类中的 myObject 只有 prop3 和 prop4 属性.

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

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

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

我该怎么做?

推荐答案

在构造函数中扩展对象(如果扩展了 Ext.Component,则在 initComponent 中扩展):

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);
    }
});

演示.

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

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