如何在文本框中显示一个值,点击"done"在sencha触摸中选择器字段中的按钮

How to display a value in a textfield on click of "done" button in picker field in sencha touch?

本文关键字:quot done sencha 选择器 按钮 字段 点击 触摸 显示 文本 一个      更新时间:2023-09-26

我正在尝试在sencha touch 2.1的文本字段中显示一个选择器字段的选定文本。我看不到任何错误在我的代码,但仍然不工作。下面是我的代码。请提供可行的解决方案。

{
    xtype : 'textfield ',
    id : 'PacingMode ',
    style : 'background - color: #585858;',
    top : '13.5%',
    usePicker : true,
    left : '20%',                                                                             
    width : '5%',                                                                         
    listeners : {
          'focus' : function(a,e, eOpts) {                                                                                                                             
                console.log("show caling");
                document.activeElement.blur();
                if (!this.picker) {
                this.picker = Ext.Viewport.add({
    xtype: 'picker',
    id: 'pacingModePickerfield',
    useTitles: true,
    slots: [{
            name: 'quantity',
            title: 'Pacing Mode',
            data: modelMgr.slotsdata1,
            valueField: 'value',
        }
    ],
    doneButton: {
        listeners: {
            // when the done button is tapped, set the value
            tap: function (button, event, eOpts) {
                var sel = document.getElementById("pacingModePickerfield");
                var text_value = sel.options[sel.selectedIndex].text;
                Ext.getCmp('PacingMode').setValue(text_value);
            }
        }
    }
});
}
this.picker.show();
},
change: function (a, e, newValue, eOpts) {
    sendValueSetRequest(this.id);
},
}

您应该使用框架从选择器中获取值:

tap: function(button, event, eOpts) {      
    var val = Ext.getCmp("pacingModePickerfield").getValues().quantity;                                                                                                                                                                                                                                                      
    Ext.getCmp('PacingMode').setValue(val);                                                                                                                         
}

试试这个

var thePicker = new Ext.Picker({
    slots: [ 
        { 
            name : 'limit_speed',
            title: 'Speed', 
            data : [ 
                {text: '50 KB/s', value: 50}, 
                {text: '100 KB/s', value: 100}, 
                {text: '200 KB/s', value: 200}, 
                {text: '300 KB/s', value: 300} 
            ] 
        }
    ],
    listeners: {
        change: function(picker, value, eOpts) {
            alert(value.limit_speed);
        }
    }
});

这是我的工作代码:

doneButton : {
   listeners : {
            tap : function(button,event,eOpts) {
                var selectedUpperSensorValue = Ext.getCmp('upperSensorPickerfield').getValue()['Upper Sensor'];
                sendSetPendingRequest("UpperSensor",selectedUpperSensorValue);
         }
    }
}