2013-02-04 44 views
2

我正在嘗試向我的按鈕添加一個偵聽器,以便當它被點擊時,它會將'textId'文本字段中的內容加載到上述文本字段上方的html文本中,按鈕。這樣,他們可以在該字段中輸入多個內容,並在以後不需要時刪除它們,因爲文本是通過刪除按鈕加載的。Uncaught TypeError:Object#<Object> has no method'getValue'

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

我越來越遺漏的類型錯誤:對象ignoreField沒有法「的getValue」當我點擊的按鈕。我不確定爲什麼textfields的getValue方法不起作用,或者我正在做一些明顯錯誤的事情。

+0

如果你路過它是文本框的id'textId'你可能想嘗試 'HTML:Ext.Container.getComponent( '文本ID')的getValue()' – cclerville

+0

getComponent不是。一個靜態方法。 –

+0

@EvanTrimboli哦,我明白了。我也注意到我的評論中有一個錯誤。我打算放的是'Ext.container.Container.getComponent'。我也正在閱讀文檔,並閱讀最好使用itemIds上面的方法,這導致了我的建議。但是你是正確的,即使那樣它不是正確的方式來使用它.http://docs.sencha.com/ext-js/4-1/#!/api/Ext.Component-cfg-itemId – cclerville

回答

0

感謝所有那些誰試圖幫助我解決這個問題。我能弄清楚我的錯在哪裏。對於我的textfields,我應該只使用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; 
} 
0

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

你能解釋一下嗎?在這一行中的分號:'ct.down('#'+ fieldId);. add(new Ext.container.Conatiner({'當它存在時,由於該行上的未檢查錯誤而導致代碼不運行,假設它是這樣的,並且在更改我的代碼以合併您提出的修復程序後,我仍然收到相同的錯誤 – ErichNova

+0

這是一個錯誤,已糾正的錯誤 –

+0

您有任何其他建議嗎?到我的代碼? – ErichNova

相關問題