Javascript 不使用Ext.getCmp获取复选框值
我正在尝试获取此复选框的值Javascript 不使用Ext.getCmp获取复选框值,javascript,scope,extjs4.1,Javascript,Scope,Extjs4.1,我正在尝试获取此复选框的值 Ext.define('myRoot.myExtApp.myForm', { extend: 'Ext.form.Panel', layout: { type: 'vbox', align: 'stretch' }, scope: this, constructor: function() { this.callParent(arguments); this.myField
Ext.define('myRoot.myExtApp.myForm', {
extend: 'Ext.form.Panel',
layout: {
type: 'vbox',
align: 'stretch'
},
scope: this,
constructor: function() {
this.callParent(arguments);
this.myFieldSet = Ext.create('Ext.form.FieldSet', {
scope: this,
columnWidth: 0.5,
collapsible: false,
defaultType: 'textfield',
layout: {
type: 'hbox', align: 'stretch'
}
});
this.mySecondForm = Ext.create('myRoot.myExtApp.myForm2', {
scope: this,
listener: this,
margin: '1 3 0 0'
});
this.myCheckBox = Ext.create('Ext.form.Checkbox', {
scope: this,
//id: 'myCheckBox',
boxLabel: 'Active',
name: 'Active',
checked: true,
horizontal: true
});
this.myFieldSet.add(this.mySecondForm);
this.myFieldSet.add(this.myCheckBox);
this.add(this.myFieldSet);
}
});
如你所见,我有另一张表格
Ext.define('myRoot.myExtApp.myForm2', {
如果我有一个处理程序,它应该从“myForm”中获取复选框的值
如果不使用Ext.getCmp,如何从Form2获取复选框的值?我知道如果我这样做,我可以得到复选框的值
Ext.getCmp('myCheckBox').getValue();
但是使用
this.myCheckBox.getValue();
给我一个未定义的错误
更新-在谨慎的建议下,我在我的表单2中尝试了这一点
this.temp=Ext.create('myRoot.myExtApp.myForm'), {});
var tempV = this.temp.myCheckBox.getValue();
我能够获得该值,但即使我取消选中该框,也能获得相同的真实值。一个解决方案可能是:
myRoot.myExtApp.myForm.myCheckBox.getValue();
小心,回答错误。有关有效的解决方案,请参阅下面的注释。我假设您担心由于过度使用组件查询而导致的性能损失。最小化组件查询的一个好方法是在闭包中定义一个新方法,以便缓存第一次
getCmp
调用的结果。将方法的定义封装在闭包中可以避免使用全局范围或无用的类属性
getMyCmp: function (cmp) {
// "cmp" does not exist outside this function
return function () {
return cmp = cmp || Ext.getCmp('#myCmp');
};
}()
你还没有发布足够的你的结构,我们需要看看它是如何结合在一起的。为了扩展Evan的回答-在
这个中,不可能知道这个的范围。myCheckBox
@Evantimboli,感谢你花时间看我的帖子。请看我的更新。我用我的完整结构编辑了它。@Izhaki。。。嗨,伊扎基,请看我更新的帖子。那会有帮助吗?你能创建一个?这真的很有帮助。@wared。。。非常感谢。但我仍然得到了未定义的错误。我试过的另一件事是在我的表格2上。。。我这样做了。temp=Ext.create('myRoot.myExtApp.myForm'),{};var tempV=this.temp.myCheckBox.getValue();。。。我得到了值,但我得到了相同的真值,即使我取消选中框对不起,我完全错了。。。“myRoot.myExtApp.myForm”指的是我们需要实例时的类。我需要更多的细节来帮助你。你的表单实例化的代码呢?谢谢你,沃德。。。你部分正确。我必须确保我声明为家长:在我的扩展类中,我所要做的就是。。。this.parent.myCheckBox.getValue();