2012-11-05 81 views
4

我有一個textfield in Sencha Touch 2和一個按鈕。當按下按鈕時,我想要輸入文本框。我用Ext.ComponentQuery試了一下,但沒有奏效。有人舉例說明如何做到這一點?獲取textfield的輸入

{ 
    xtype: 'textfield', 
    cls: 'inputfields', 
    id: 'title', 
}, 
{ 
    xtype: 'button', 
    ui: 'action', 
    name: 'textfieldButton', 
    handler : function(){ 
     // what should go here ? 
    } 
} 
+1

提示:不要在標題中寫入Sencha Touch 2,請添加sencha-touch-2標籤。然後更容易找到Sencha Touch 2助手。 –

回答

2

你可以這樣做:

var value = Ext.ComponentQuery.query('#title')[0].getValue(); 
// test by writing in console 
console.log(value); 

提示1:這是有幫助的煎茶的API reference當你使用這個框架(同樣用於其他任何框架打開所有的時間,編程語言等。 )。爲了速度,我建議下載它。
TIP 2:在鉻Ctrl鍵 + + 爲開發工具;你可以在那裏訪問控制檯。

+0

它穿着!非常感謝。 – Lizzy249

+0

@ Lizzy249如果您發現它有幫助,請接受答案。 –

+2

+1提示。雖然我會建議使用itemIds而不是id,以避免與Ext.ComponentManager衝突。 –

4

我做這件事的方式是Ext.getCmp('title').getValue();

也請參閱文檔(Docs API)。他們真的很有幫助。