简体   繁体   English

无法调用未定义的on方法

[英]Cannot call method of on of undefined

I was wondering if someone could tell me why the below code is not working. 我想知道是否有人可以告诉我下面的代码为什么不起作用。 The first 2 on functions are working and then the last on function is not working and I am getting the error message "cannot call method of on of undefined." 前两个on函数正常工作,然后最后一个on函数无效,我收到错误消息“无法调用on of undefined的方法”。

It seems to not like this line, textF.getEl().on('click', function() { 似乎不喜欢这一行,textF.getEl()。on('click',function(){

    bUpdateSwitch.on({'click': function (){
        var textF = Ext.getCmp('rateSummary');
        textF.enable();
        textF.getEl().on('click', function() {
            Ext.getCmp('rtCurrency').enable();
            Ext.getCmp('rtCurrency').setReadOnly(false); 
            Ext.getCmp('rtAccEffDate').enable(); 
            Ext.getCmp('rtAccEffDate').setReadOnly(false); 
            Ext.getCmp('rtAccExDate').enable(); 
            Ext.getCmp('rtAccExDate').setReadOnly(false); 
            Ext.getCmp('rtJctR260').enable(); 
            Ext.getCmp('rtJctR260').setReadOnly(false); 
            Ext.getCmp('switchRate').enable(); 
            Ext.getCmp('switchRate').setReadOnly(false);       
        });
    }})

That means that your rateSummary component is not rendered at the time this function is executed. 这意味着执行此功能时不会呈现rateSummary组件。 Hence getEl() returns undefined and calling a method on undefined crashes with the error message you've reported... 因此, getEl()返回undefined并在undefined崩溃时调用方法,并报告您所报告的错误消息...

What is this component exactly? 这个组件到底是什么? Can you not register the listener on the component directly, instead of its element? 您不能直接在组件上注册侦听器,而不是在其元素上注册吗? Like this: 像这样:

textF.on('click', function() {
    // ...
});

Otherwise, do it like this, and Ext will take care of waiting for the rendering: 否则,请按照以下步骤进行操作,Ext将负责等待渲染:

textF.on({
    el: {
        // ...
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM