如何在 extjs4 中不使用 Ext.getCmp() 的情况下启用/禁用表单按钮?

发布于 2025-01-02 11:42:50 字数 715 浏览 1 评论 0原文

这是以下表单,我想访问表单内的表单应用按钮,而不使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

那支青花 2025-01-09 11:42:50

您可以使用控制器来侦听此表单触发的“dirtychange”事件。

//controller init 
init: function() {
    this.control({
        'form': {
            dirtychange: function(form) {
                var button = form.owner.query('button[text=Apply]');
                button[0].enable();             
            }
        }
    });
}

达伦给出的答案肯定会起作用,这只是利用组件查询为您提供一种不同的方式来访问和控制组件。例如,如果您想在表单中启用一系列按钮,您可以删除“text=Apply”,然后将返回所有表单按钮的数组。

You can use a controller to listen for the 'dirtychange' event fired by this form.

//controller init 
init: function() {
    this.control({
        'form': {
            dirtychange: function(form) {
                var button = form.owner.query('button[text=Apply]');
                button[0].enable();             
            }
        }
    });
}

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.

饭团 2025-01-09 11:42:50

使用构造函数,然后您可以在其中创建按钮,然后在表单中引用它。一旦您在表单中获得了引用,您就可以从那里的侦听器中检索它。看起来像这样:

contructor: function(config) {
   this.button = new Ext.Button({
       // Provide your button config here
   });
}

listeners: {
   dirtychange: function(sm) {
       this.button.enable();
   }
}

不使用 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:

contructor: function(config) {
   this.button = new Ext.Button({
       // Provide your button config here
   });
}

listeners: {
   dirtychange: function(sm) {
       this.button.enable();
   }
}

That should work without using Ext.getCmp()

星光不落少年眉 2025-01-09 11:42:50

同意 jthirau - 绝对使用组件查询。

执行您正在执行的操作的另一种方法是简单地添加按钮处理程序。这在按钮配置上是正确的:

handler:function(){
  //do something
}

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:

handler:function(){
  //do something
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文