似乎无法响应 sencha touch 中的事件火灾

发布于 2024-12-29 08:39:42 字数 1560 浏览 3 评论 0原文

我正在尝试在 sencha touch 中触发自定义事件,它似乎被添加到可以触发的事件中,并且它似乎触发了,但我的侦听器似乎没有响应该事件。

事件在这里实例化,这是表单主体:

Ext.apply(this, {
        scroll: 'vertical',
        dockedItems: [ titlebar, buttonbar ],
        items: [ fields ],
        listeners: {
            beforeactivate: function() {
                var saveButton = this.down('#userFormSaveButton');
                    saveButton.setText('Submit');
                    this.addEvents('cityUpdate');
                    console.log('event added');

            },
            deactivate: function() {
                this.resetForm();
            }
        }
    });

然后在此处触发事件:

  if (result.data != 'false' && result.data.state) {
        Ext.getCmp("usersForm").fireEvent('cityUpdate', result.data.towns);
        console.log('event fired');
        alert('Your town is ' + result.data.towns + ' ' + result.data.state.replace( /\+/g , ' ' ));

    }

然后将侦听器应用于此处表单中的字段:

                {
                xtype: 'textfield',
                name: 'city',
                label: 'City*',
                placeHolder: 'New York',
                useClearIcon: true,
                id:'city',
                listeners: {
                    cityUpdate: function(city) {
                        console.log('event reponse' , this.fieldEl.dom , city);
                    }
                }
            },

有人可以向我解释一下为什么我看不到事件响应调用控制台?我看到添加了事件并触发了事件,但我似乎从未让事件实际运行事件响应控制台语句。我在控制台中没有收到任何错误,所以我对这里发生的情况有些茫然?

I'm trying to fire a custom event in sencha touch, and it seems to get added to the events that can be fired, and it appears to fire, but my listener does not seem to respond to the event.

the event is instantinated here, where this is the form body:

Ext.apply(this, {
        scroll: 'vertical',
        dockedItems: [ titlebar, buttonbar ],
        items: [ fields ],
        listeners: {
            beforeactivate: function() {
                var saveButton = this.down('#userFormSaveButton');
                    saveButton.setText('Submit');
                    this.addEvents('cityUpdate');
                    console.log('event added');

            },
            deactivate: function() {
                this.resetForm();
            }
        }
    });

The event is then fired here:

  if (result.data != 'false' && result.data.state) {
        Ext.getCmp("usersForm").fireEvent('cityUpdate', result.data.towns);
        console.log('event fired');
        alert('Your town is ' + result.data.towns + ' ' + result.data.state.replace( /\+/g , ' ' ));

    }

Then the listener is applied to a field in the form here:

                {
                xtype: 'textfield',
                name: 'city',
                label: 'City*',
                placeHolder: 'New York',
                useClearIcon: true,
                id:'city',
                listeners: {
                    cityUpdate: function(city) {
                        console.log('event reponse' , this.fieldEl.dom , city);
                    }
                }
            },

Can someone explain to me why I am not able to see the event response call in the console? I see event added and event fired, but I never seem to get the event to actually run the event responded console statement. I receive no errors in the console, so I'm at somewhat of a loss as to what is happening here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

獨角戲 2025-01-05 08:39:42

看起来表单正在触发事件,但您已将侦听器添加到表单上的文本字段中。

如果 usersForm 是调用 fireEvent 的那个,那么该事件的侦听器需要位于 usersForm 本身上。

如果将 cityUpdate 处理程序添加到第一个代码片段中,与 beforeactivatedeactivate 位于同一块中,会发生什么?这能抓住事件吗?如果是这样,你没想到它会被抓到那里吗?如果是这样,可能是一个轻微的设计问题。

It looks like the form is firing the event, but you've added the listener to a textfield that is on the form.

If usersForm is the one that calls fireEvent, then the listener for that event needs to be on usersForm itself.

What happens if you add a cityUpdate handler to the first snippet of code, in the same block as beforeactivate and deactivate? Does that catch the event? If so, were you not expecting it to be caught there? Might be a slight design problem if so.

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