【问题标题】:How to attribute a property from parent to the child in javascript? (OOP)如何在javascript中将属性从父级属性分配给子级? (哎呀)
【发布时间】:2013-07-07 01:14:42
【问题描述】:

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

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

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

【问题讨论】:

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

标签: javascript oop object extjs touch


【解决方案1】:

在你的类定义中,你应该重写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);
    }
});

【讨论】:

    猜你喜欢
    • 2022-09-30
    • 2021-06-28
    • 2020-02-11
    • 1970-01-01
    • 2018-01-15
    • 2021-10-18
    • 2013-07-28
    • 2021-11-05
    • 2011-11-06
    相关资源
    最近更新 更多