简体   繁体   English

未捕获的TypeError:对象# <Object> 没有方法&#39;getValue&#39;

[英]Uncaught TypeError: Object #<Object> has no method 'getValue'

I am currently attempting to add a listener to my button so that when it is clicked it loads what is in the 'textId' textfield into an html text above said textfield and button. 我目前正在尝试将侦听器添加到我的按钮,以便在单击它时将“ textId”文本字段中的内容加载到上述文本字段和按钮上方的html文本中。 This is so they can enter multiple things into this field and delete them if one is not needed afterwards because the text gets loaded in with a delete button. 这样一来,他们便可以在该字段中输入多项内容,如果以后不需要,则可以将其删除,因为文本是通过删除按钮加载的。

createTextAndButton: function(fieldId, v, textId, field, text, num) {
    var n = new Number(num);
    var ct = new Ext.container.Container({
        xtype:"container",
        layout:"vbox",
        //padding:"5 0",
        items: [{
            xtype:"container",
            itemId: fieldId,
            }, {
            xtype: "container",
            layout:"hbox",
            padding: "5 0",
            items: [{
                xtype: 'textfield',
                vtype: v,
                name: textId,
                fieldLabel: field,
                validateOnBlur: true
            }, {
                xtype: "button",
                text: text,
                width: 115,
                handler: function() {
                    ct.down('#' + fieldId).add(Ext.ComponentMgr.create({
                        xtype: "container",
                        itemId: 'entry' + n,
                        layout: "hbox",
                        padding: "5 0",
                        items: [{
                            xtype: "component",
                            html: "<p>" + textId.getValue() + "</p>"
                        }, {
                            xtype: "button",
                            itemId: 'dButton',
                            text: "delete",
                            width: 80
                            }
                        }]
                    }));
                    n++;
                }
            }]
        }]
    });
    return ct;
}

I'm getting Uncaught TypeError: Object ignoreField has no method 'getValue' when I click on the button. 我收到未捕获的TypeError:单击按钮时,对象ignoreField没有方法'getValue'。 I'm unsure why the textfields getValue method is not working or if I am doing something obviously wrong. 我不确定为什么textfields的getValue方法不能正常工作,或者我做错了什么。

itemId is local to a particular container, getCmp() will only retrieve the global id for a component. itemId对于特定容器是本地的,getCmp()将仅检索组件的全局ID。

It would be much easier to do something like: 进行以下操作会容易得多:

createTextAndButton: function(fieldId, type, v, textId, field, text) {
    var ct = new Ext.container.Container({
        xtype:"container",
        layout:"vbox",
        //padding:"5,0",
        items: [{
            xtype:"container",
            itemId: fieldId,
            },{
            xtype: "container",
            layout:"hbox",
            padding: "5 0",
            items: [{
                xtype: type,
                vtype: v,
                itemId: textId,
                fieldLabel: field,
                validateOnBlur: true
            }, {
                xtype: "button",
                text: text,
                width: 115,
                handler: function() {
                    ct.down('#' + fieldId).add(new Ext.container.Container({
                        xtype: "container",
                        padding: "5 0",
                        items: [{
                            xtype: "component",
                            autoEl: "pre",
                            html: textId.getValue()
                        }, {
                            xtype: "button",
                            text: "delete",
                            width: 115
                        }]
                    }));
                }
            }]
        }]
    });
    return ct;
}

Thanks to all those who attempted helping me solve this question. 感谢所有尝试帮助我解决此问题的人。 I was able to figure out where my fault was. 我能够弄清楚我的错在哪里。 for my textfields I should be using just the id: tag not name: or itemId Here is the working code for those who care. 对于我的文本字段,我应该只使用id:标签而不是name:itemId这是那些关心的人的工作代码。

createTextAndButton: function(fieldId,  textId, field, text, num) {
    var n = new Number(num);
    var ct = new Ext.container.Container({
        xtype:"container",
        layout:"vbox",
        //padding:"5 0",
        items: [{
            xtype:"container",
            itemId: fieldId,
            }, {
            xtype: "container",
            layout:"hbox",
            padding: "5 0",
            items: [{
                xtype: 'textfield',
                id: textId,
                fieldLabel: field,
                validateOnBlur: true
            }, {
                xtype: "button",
                text: text,
                width: 115,
                handler: function() {
                    ct.down('#' + fieldId).add(Ext.ComponentMgr.create({
                        xtype: "container",
                        Id: 'entry' + n,
                        layout: "hbox",
                        padding: "5 0",
                        items: [{
                            xtype: "component",
                            html: "<p>" + Ext.getCmp(textId).getValue() + "</p>"
                        }, {
                            xtype: "button",
                            itemId: 'dButton',
                            text: "delete",
                            width: 80
                        }]
                    }));
                    n++;
                }
            }]
        }]
    });
    return ct;
}

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

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