如何使用Sencha Touch中列表选择的值填充文本字段?

时间:2011-07-17 18:59:06

标签: javascript listview sencha-touch

我有一个文本字段,我有一个列表。我想用列表选择中的记录填充文本字段。我怎样才能做到这一点?我正在使用Sencha Touch进行应用程序。

这是我的列表代码:

var airports = new Ext.List({
    fullscreen: true,
    id: 'list',
    indexBar: false,
    itemTpl : '{firstName} {lastName}',
    listeners:{
       change: function() {
        var el = Ext.getDom('from'); 
        el.setValue(this.getValue())
       }

    },
    store: store

});

这是我的文本域代码:

{
    xtype: 'textfield',
    name : 'from',
    label: 'From',
    id: 'from',
    labelWidth: '23%',
    placeHolder: 'Search airport',
    readOnly : true,
    listeners: {'render': function(cmp) { 
            cmp.getEl().on('click', function( event, el ) {
                                NotiflyApp.views.viewport.setActiveItem('ListContainer', {type: 'fade'});
            });            
    }}
},

2 个答案:

答案 0 :(得分:1)

Okey,所以我设法通过阅读this tutorial解决了这个问题。

以下是列表代码:

var fromAirports = new Ext.List({
    fullscreen: true,
    id: 'airportList',
    indexBar: false,
    itemTpl : '{airport} {IATAcode}',
    onItemTap: function(item, index) {
    var formField = NotiflyApp.views.formField;
    var selectedAirport = store.getAt(index).get('firstName');
    var selectedIATA = store.getAt(index).get('lastName');
    var from = Ext.ModelMgr.create(
        { from: selectedAirport + ' ' + selectedIATA }, 'Contact');
        NotiflyApp.views.formField.load(from);
        NotiflyApp.views.viewport.setActiveItem('formInput', {type: 'fade'});
        },

    store: store
});

希望这有帮助!如果你在实施它时遇到问题,请发表评论,我会尽力帮助你!

答案 1 :(得分:1)

我和你一样(我猜) - 一个列表和一个表单 - 我想用我列表中的项填充字段

如果是你想要的,你可以在onItemDisclosure函数中尝试这个:

      var dataName= record.store.data.getAt(index).data.dataName;
      var dataSurname= record.store.data.getAt(index).data.dataSurname;

然后在表单字段中,您可以尝试:

      Ext.getCmp('name').setValue(dataName);
      Ext.getCmp('surname').setValue(dataSurname);

我不知道这是不是一种大的解决方法,但它对我有用:)我希望我能帮忙!!