【问题标题】:How to get value from input component element in ExtJs如何从 ExtJs 中的输入组件元素中获取值
【发布时间】:2014-03-02 04:09:12
【问题描述】:

这是我的代码:

xtype: 'component',
autoEl: {
    html: '<input type="text">'
},
listeners: {
    render: function(_component) {
        _component.getEl().on('keyup', function(e) {
            console.log(_component.getValue());
        });
    }
}

如您所见,每次在输入中按下一个键时,我都会尝试输出输入的值。但是,控制台输出错误,内容为“Uncaught TypeError: Object [object Object] has no method 'getValue'”

如何获取此文本框的值?

【问题讨论】:

    标签: javascript extjs


    【解决方案1】:

    我认为最好以“ExtJS”方式声明事件。

    xtype: 'panel',
    items: [
        { xtype: 'textfield', id: 'inputtext' }
    ]
    

    在你的控制器中:

    onLaunch: function () {
        this.control({
            '#inputtext': {
                keyup: function(e) {
                   console.log(e.getValue());
                }
            }
        });
    }
    

    我的想法是 ExtJS 不喜欢我们直接弄乱 DOM

    【讨论】:

    • 谢谢,但我对 extJs 还是很陌生,我不知道如何将它插入到我的控制器中。我的控制器只是Ext.define('RateManagement.controller.Main', { extend: 'Ext.app.Controller' }); ,上面发布的代码在我的视图中(views/Main.js)。
    • 只需在扩展属性之后(右大括号之前)添加帖子的“onLaunch”部分。我强烈建议您查看有关该主题的大量示例:dev.sencha.com/deploy/ext-4.0.0/examples
    • 在您的示例中,_component 定义在哪里?
    • 我通过面板更改了您的组件。但它是可变的,面板是一种特定类型的组件。但是你不应该直接使用 _component 。这不是一个好习惯。
    • 例如,在我的代码中,我在此处设置了_component render: function(_component) {,但是您的示例中我在哪里设置了它?我问是因为我无法让这段代码工作。控制台中不会抛出任何错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-14
    • 2018-08-13
    • 2012-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多