拉力赛场的听众

时间:2014-09-10 20:02:38

标签: rally appsdk2

我想从输入文本字段“workItemTextField”中获取文本值,但我无法使用以下代码触发keypress事件。

Ext.define('CustomApp', {
    extend: 'Rally.app.App',
    componentCls: 'app',
    _onWorkItemKeyPress: function() {
        console.log('In _onWorkItemKeyPress');
        console.log(this);
    },
    launch: function() {
        this.add({
            title: 'Time Entry',
            width: 800,
            padding: 10,
            bodyPadding: 10,
            renderTo: Ext.getBody(),
            layout: {
                type: 'vbox',
                align: 'bottom'
            },
            items: [
            {
                xtype: 'rallytextfield',
                itemId: 'workItemTextField',
                fieldLabel: 'Work Item ID',
                labelAlign: 'top',
                listeners: {
                    scope: this,
                    keypress: this._onWorkItemKeyPress
                }
            }]
        });
    }
});

我能够用它来取代听众:

listeners: {
    keypress: {
        element: 'el',
        fn: this._onWorkItemKeyPress
    }
}

但它没有回归我所期望的。 “this”是文本字段,但我不能在其上调用getValue(),而我期望传入的属性(从查看api)并不是我所期望的。第一个arg是事件,第二个不确定,第三个是html元素。

我正在使用apps / 2.0rc3 / sdk.js。我查看了我可以在网上找到的所有代码,看起来我正在为此做好准备,但肯定有一些我遗漏的东西。我做错了什么?

1 个答案:

答案 0 :(得分:1)

我可以通过使用specialkey设置等待ENTER,然后调用_onWorkItemKeyPress(field)来获取拉力文本字段的值。 field.getValue()适用于此案例。除非您的目标不是获取用户输入的完整值,否则最好不要使用按键并等到用户表明他们已完成输入。

Ext.define('CustomApp', {
    extend: 'Rally.app.App',
    componentCls: 'app',
    items:{ html:'<a href="https://help.rallydev.com/apps/2.0rc3/doc/">App SDK 2.0rc3 Docs</a>'},
    launch: function() {
        var that = this;
        that.add({
            title: 'My Text',
            itemId:'mytext',
            width: 800,
            padding: 10,
            bodyPadding: 10,
            layout: {
                type: 'vbox',
                align: 'bottom'
            },
            items: [
            {
                xtype: 'rallytextfield',
                itemId: 'workItemTextField',
                fieldLabel: 'Work Item ID',
                labelAlign: 'top',
                listeners: {
                    specialkey: function(field, e){
                        // e.HOME, e.END, e.PAGE_UP, e.PAGE_DOWN,
                        // e.TAB, e.ESC, arrow keys: e.LEFT, e.RIGHT, e.UP, e.DOWN
                        if (e.getKey() == e.ENTER) {
                            that._onWorkItemKeyPress(field);
                        }
                        else{
                            console.log('?');
                        }
                    }
            }
            }]
        });
    },
    _onWorkItemKeyPress:function(field){
        console.log('value:',field.getValue());
    }
});