获取文本字段的输入

时间:2012-11-05 20:47:44

标签: extjs sencha-touch-2 textfield

我在 Sencha Touch 2 中有一个 textfield 和一个按钮。我想在按下按钮时获得 textfield 的输入。我尝试使用Ext.ComponentQuery,但它没有用。有人举个例子怎么做?

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

2 个答案:

答案 0 :(得分:4)

我的做法是Ext.getCmp('title').getValue();

另请参阅文档(Docs API)。他们真的很有帮助。

答案 1 :(得分:2)

你可以这样做:

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

提示1:当您使用此框架时(同样适用于任何其他框架,编程语言等),让Sencha API reference始终打开是有帮助的。为了速度,我建议下载它。
提示2:在Chrome中 Ctrl + Shift + I 用于开发人员工具;你可以在那里访问控制台。