如何在 extjs4 中不使用 Ext.getCmp() 的情况下启用/禁用表单按钮?
这是以下表单,我想访问表单内的表单应用按钮,而不使用 Ext.getCmp() 并为按钮定义 id:
{xtype : 'form',
url : 'index.php/submitform',
trackResetOnLoad : true,
id : 'generalprofilebasicinformation'+ this.getId(),
listeners : {
//is fired when the form is dirty(field values are modified)
dirtychange : {
fn : function(sm) {
//Here Is my problem:
//How to access to Apply button or any other buttons defined inside the form???
var applyButton = this.Button;
applyButton.enable();}}},
buttons : [{
text : 'Apply',
formBind : true, // only
// enabled
// once the
// form is
// valid
disabled : true,} ]}
Here is the following form and i wanna access form`s apply button inside the form without using Ext.getCmp() and defining an id for the button:
{xtype : 'form',
url : 'index.php/submitform',
trackResetOnLoad : true,
id : 'generalprofilebasicinformation'+ this.getId(),
listeners : {
//is fired when the form is dirty(field values are modified)
dirtychange : {
fn : function(sm) {
//Here Is my problem:
//How to access to Apply button or any other buttons defined inside the form???
var applyButton = this.Button;
applyButton.enable();}}},
buttons : [{
text : 'Apply',
formBind : true, // only
// enabled
// once the
// form is
// valid
disabled : true,} ]}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用控制器来侦听此表单触发的“dirtychange”事件。
达伦给出的答案肯定会起作用,这只是利用组件查询为您提供一种不同的方式来访问和控制组件。例如,如果您想在表单中启用一系列按钮,您可以删除“text=Apply”,然后将返回所有表单按钮的数组。
You can use a controller to listen for the 'dirtychange' event fired by this form.
The answer darren gave will certainly work, this just utilizes component queries to give you a different way to reach and control components. If you wanted to enable a series of buttons within the form, for example, you could remove the 'text=Apply' and an array of all the forms buttons will be returned.
使用构造函数,然后您可以在其中创建按钮,然后在表单中引用它。一旦您在表单中获得了引用,您就可以从那里的侦听器中检索它。看起来像这样:
不使用 Ext.getCmp() 就应该可以工作
Use a constructor and then you can create the button inside it and then have a reference to it in your form. Once you have the reference in the form, you can then retrieve it from the listener you have there. Would look like this:
That should work without using Ext.getCmp()
同意 jthirau - 绝对使用组件查询。
执行您正在执行的操作的另一种方法是简单地添加按钮处理程序。这在按钮配置上是正确的:
Agreed with jthirau - definitely use component query.
Another way to do what you are doing is to simply add a button handler. This goes right on the button config: