gpt4 book ai didi

javascript - Extjs 如何在组件中创建 getter/setter

转载 作者:行者123 更新时间:2023-11-30 08:10:11 24 4
gpt4 key购买 nike

我有一段代码,我在其中创建了一个组件。单击“应用”后,我想保存此表单字段对象并可供 getter 使用。这样父容器就可以读取它。

我还想要所有字段的 getter/setter,以便可以在运行时更新值。如何实现?

Ext.define('MyApp.view.MyForm', {
extend: 'Ext.form.Panel',

height: 463,
width: 227,
bodyPadding: 10,
title: 'My Form',

initComponent: function() {
var me = this;

Ext.applyIf(me, {
items: [
{
xtype: 'textfield',
fieldLabel: 'Component Name',
anchor: '100%'
},
{
xtype: 'textfield',
fieldLabel: 'Host',
anchor: '100%'
},
{
xtype: 'textfield',
fieldLabel: 'Port',
anchor: '100%'
},
{
xtype: 'textfield',
fieldLabel: 'Path',
anchor: '100%'
},
{
xtype: 'textareafield',
fieldLabel: 'Request Data',
anchor: '100%'
},
{
xtype: 'button',
text: 'Apply',
listeners: {
click: {
fn: me.onButtonClick,
scope: me
}
}
}
]
});

me.callParent(arguments);
},
onButtonClick: function(button, e, options) {
var form = this.getForm(),
values = form.getFieldValues(),
//make this available to public
json = Ext.JSON.encode(values);
console.log(json);


}

});

最佳答案

为了实现这一点,需要在配置中定义所有变量:{} extjs 将自动创建 getter/setter。

然后您可以使用 this.getVar()、this.setVar() 引用它

希望对初学者有所帮助。

关于javascript - Extjs 如何在组件中创建 getter/setter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11623789/

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