gpt4 book ai didi

javascript - 如何在 extjs 中获取构造函数的参数?

转载 作者:搜寻专家 更新时间:2023-11-01 05:26:43 24 4
gpt4 key购买 nike

我有一些课

AddOrgWindowUI = Ext.extend(Ext.Window, {
title: 'form',
width: 400,
height: 198,
layout: 'form',
padding: 5,
initComponent: function() {
this.items = [
{
xtype: 'textfield',
fieldLabel: 'parapapa',
anchor: '95%',
value: m,
emptyText: 'perapapa'
}
];
AddOrgWindowUI.superclass.initComponent.call(this);
}});

当我创建一个对象时 var AddOrgWindowForm = new AddOrgWindowUI('aaa'); 我想将 arg ('aaa') 设为我的新表单值(值 m)。怎么得到?我正在尝试 initComponent: function(m) { 但它不起作用。

最佳答案

initComponent 函数在 Ext.Window 的基类之一内部调用。您不应该尝试直接调用它。这就是它不会处理您自己的参数的原因。

所以我推荐你在extending ExtJS classes时使用标准形式的参数.

它就像用您想要覆盖的属性或方法初始化对象一样简单(或者插入以防属性不在其中)。然后只需使用 this 关键字即可访问它们。

这是可能的,因为对于每个 Ext.Component 及其子类,传递给构造函数的第一个参数应该是一个对象,并且该对象中的每个成员都将被复制到构造的新对象中。大多数 ExtJS 类直接或间接地从 Ext.Component 扩展,并且您从 Ext.Window 扩展,而 Ext.Window 也从 Ext.Component 扩展。

这里你有你的例子固定:

var AddOrgWindowUI = Ext.extend(Ext.Window, {
title: 'form',
width: 400,
height: 198,
layout: 'form',
padding: 5,

initComponent: function() {
this.items = [
{
xtype: 'textfield',
fieldLabel: 'parapapa',
anchor: '95%',
value: this.initialValue,
emptyText: 'perapapa'
}
];
AddOrgWindowUI.superclass.initComponent.call(this);
}
});

function test() {
var AddOrgWindowForm = new AddOrgWindowUI({initialValue:'aaa'});
AddOrgWindowForm.show();
}

关于javascript - 如何在 extjs 中获取构造函数的参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3627403/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com