Ext JS将额外的参数传递给处理程序 [英] Ext JS pass extra param to handler

查看:131
本文介绍了Ext JS将额外的参数传递给处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将额外的参数传递给messageBox的处理函数.

I want to pass extra parameter to handler function of messageBox.

我已经创建了这样的上下文菜单:

I've created a context menu like this:

    onEventContextMenu: function (s, rec, e) {
    e.stopEvent();

    if (!s.ctx) {
        s.ctx = new Ext.menu.Menu({
            items: [{
                text: 'Delete event',
                iconCls: 'icon-delete',
                scope: this,
                handler : function() {
                Ext.MessageBox.show({
                                title : 'Reason',
                                msg : 'place reason:',
                                width : 300,
                                buttons : Ext.MessageBox.OKCANCEL,
                                multiline : true,
                                fn : this.showResultText(buttonId, text, rec)
                            });
                }
            }]
        });
    }
    s.ctx.rec = rec;
    s.ctx.showAt(e.getXY());
},

showResultText : function (btn, text, record){
alert(btn);
    if (btn == 'cancel') {
        alert(text + ' cancel');
    }
    if (btn == 'ok') {
        alert(record.get('Name'));
    }
},

因此,当用户单击删除"事件时,他可以输入执行此操作的原因. 他按ok或取消后,我致电处理程序.我可以在其中访问按钮和文本,但是我需要传递额外的参数.

So than when user click on Delete event he can enter reason why he is doing that. After he press ok or cancel I call handler. I can access button and text in there, but I need to pass extra param.

通过阅读Sencha文档,我发现了这一点:

Reading Sencha documentation I found this:

fn:功能

fn : Function

当通过单击配置的按钮,对话框关闭按钮或按返回按钮输入输入来关闭对话框时调用的回调函数.

A callback function which is called when the dialog is dismissed either by clicking on the configured buttons, or on the dialog close button, or by pressing the return button to enter input.

进度和等待对话框将忽略此选项,因为它们不响应用户操作,并且只能以编程方式关闭,因此在关闭对话框后,应使用相同的代码调用任何必需的函数.传递的参数:

Progress and wait dialogs will ignore this option since they do not respond to user actions and can only be closed programatically, so any required function should be called by the same code after it closes the dialog. Parameters passed:

参数

-buttonId:字符串 按下的按钮的ID,其中之一: 好的 是的 不 取消

-buttonId : String The ID of the button pressed, one of: ok yes no cancel

-text:字符串 如果提示符或多行为true,则输入字段的值

-text : String Value of the input field if either prompt or multiline is true

-opt:对象 传递给show的配置对象.

-opt : Object The config object passed to show.

但是我还是无法正常工作:(

But still I cant get this working :(

推荐答案

我通常采用的方法是通过scope参数传递其他数据:

The approach that I usually take is to pass additional data via the scope parameter:

Ext.MessageBox.show({
   ...
   scope: {
      obj: this,
      record: rec
   },
   fn: function(buttonId, text, option) {
      // Access properties specified in the 'scope' parameter via 'this'
      var obj = this.obj,
          record = this.record;

      obj.showResultText(buttonId, text, record);
   }
});

这篇关于Ext JS将额外的参数传递给处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆