如何在javascript中将属性从父属性属性赋予子属性?(OOP)

How to attribute a property from parent to the child in javascript? (OOP)

本文关键字:属性 OOP javascript      更新时间:2023-09-26

我正在开发一个sencha触摸应用程序,如果a能做这样的事情,那就太好了:

Ext.define('PUREM.view.screen.Form', {
    person : null,
    items : [
        {xtype: 'mycomponent', person: parent.person}
    ]
});

显然这段代码不起作用。我想知道如何让它工作,如果有办法在子对象中使用父对象的"person"属性(xtype:'mycomponent')。

在类定义中,应该覆盖initComponent函数。然后,您将可以访问对象的所有属性。

Ext.define('PUREM.view.screen.Form', {
    extend: 'Ext.form.Panel',
    config: {
        person : null
    },
    initComponent: function() 
    {
        var me = this;
        me.items = [
            {xtype: 'mycomponent', person: me.person}
        ]
        me.callParent(arguments);
    }
});