簡體   English   中英

未捕獲的TypeError:對象# <Object> 沒有方法&#39;getValue&#39;

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

我目前正在嘗試將偵聽器添加到我的按鈕,以便在單擊它時將“ textId”文本字段中的內容加載到上述文本字段和按鈕上方的html文本中。 這樣一來,他們便可以在該字段中輸入多項內容,如果以后不需要,則可以將其刪除,因為文本是通過刪除按鈕加載的。

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;
}

我收到未捕獲的TypeError:單擊按鈕時,對象ignoreField沒有方法'getValue'。 我不確定為什么textfields的getValue方法不能正常工作,或者我做錯了什么。

itemId對於特定容器是本地的,getCmp()將僅檢索組件的全局ID。

進行以下操作會容易得多:

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;
}

感謝所有嘗試幫助我解決此問題的人。 我能夠弄清楚我的錯在哪里。 對於我的文本字段,我應該只使用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