3

我想在用户更改 ExtJS 4 中的 HtmlEditor 的内容时捕获。我尝试了同步、更改和推送事件,但均未成功。每当获得焦点时,似乎都会触发同步,不会触发更改,而且我不知道是什么原因导致推送被触发。

当用户更改 HtmlEditor 的内容时,谁能知道触发了哪个事件?

谢谢

编辑:我尝试了以下对我不起作用的代码,有什么想法吗?

init: function() {
    this.control({
        'htmleditor[name="reportHtmlEditor"]': {
            render: this.addKeyHandler
        }
    });
},

addKeyHandler: function(field) {
    // This gets called fine on the component render
    var el = field.textareaEl;
    if (Ext.isGecko) {
        el.on('keypress',
        function() {
            // Do Stuff, which never gets called
        }, this, { buffer: 100});
    }
    if (Ext.isIE || Ext.isWebKit || Ext.isOpera) {
        el.on('keydown',
        function() {
            // Do Stuff, which never gets called
        }, this, { buffer: 100});
    }
},

有关更多信息,我正在使用 Firefox 进行测试,并且我从这篇文章中获得了其他信息。

4

1 回答 1

2

看起来有用于编辑源的文本区域。此字段与 html 中的任何其他字段一样,仅在模糊后触发更改事件(HtmlEditor 似乎依赖此事件)。您可能应该绑定到其他事件,例如keydown,然后根据按下的键,触发适当的事件。您可以在渲染处理程序中执行此操作:

{
    xtype: 'htmleditor',
    listeners: {
        render: function(){
            this.textareaEl.on('keydown', function() {
                this.fireEvent('sync', this, this.textareaEl.getValue());
            }, this, { buffer: 500 });
        },
        sync: function(sender, html){
            debugger;
        }
    }
}
于 2011-12-07T06:59:53.533 回答