我有一个文本字段和一个列表。我想用列表选择中的记录填充文本字段。我怎样才能做到这一点?我正在 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'});
});
}}
},
最佳答案
好的,所以我通过阅读 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
});
希望这有帮助!如果您在实现时遇到问题,请发表评论,我会尽力帮助您!
关于javascript - 如何使用 Sencha Touch 中列表选择的值填充文本字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6726038/