作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有一些课
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/
我是一名优秀的程序员,十分优秀!