【问题标题】:Get input of textfield获取文本字段的输入
【发布时间】:2012-11-05 20:47:43
【问题描述】:

我在 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 ?
    }
}

【问题讨论】:

  • 提示:不要在标题中写 Sencha Touch 2,而是添加一个 sencha-touch-2 标签。然后更容易找到 Sencha Touch 2 助手。

标签: extjs sencha-touch-2 textfield


【解决方案1】:

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

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

【讨论】:

    【解决方案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 for开发者工具;您可以在那里访问控制台。

    【讨论】:

    • 它穿了!非常感谢。
    • +1 提示。虽然我建议使用 itemIds 而不是 ids 以避免 id 与 Ext.ComponentManager 冲突。
    猜你喜欢
    • 2022-11-01
    • 2018-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多