如何处理sencha touch中的选项控件的监听器

时间:2011-10-10 11:10:53

标签: sencha-touch extjs

我有一个应用程序,我正在使用选项控件。现在我不知道当使用sencha touch在选项控件中更改选项时,我如何处理事件。以下是下面的代码,其中包含选项。任何帮助都非常感谢。

Ext.regModel('Contact', {
    fields: ['firstName', 'lastName']
});

var store1 = new Ext.data.JsonStore({
    model  : 'Contact',
    autoLoad : true,
           autoDestroy : true, 
    data: [
        {firstName: 'Tommy',   lastName: 'Maintz'},
        {firstName: 'Rob',     lastName: 'Dougan'},
        {firstName: 'Ed',      lastName: 'Spencer'},        
        {firstName: 'Abraham', lastName: 'Elias'},
        {firstName: 'Jay',     lastName: 'Robinson'}
    ]
});

new Ext.Application({
    launch: function() {
       var panel =  new Ext.Panel({
            fullscreen: true,
            id:'thePanel',
            layout: 'auto',
            style: 'background-color:darkblue',
            scroll:'vertical'
        });
//do this in your dynamically called function
    var list = new Ext.List({
        id :'theList',
        itemTpl : '{firstName} {lastName}',
        store: store1,
        width: '100%',
        scroll:false
    });

var stateList = new Ext.form.Select({
    label : 'State',
    name: 'state',
    widht: '100%',
    options: [
        {text: 'First Option',  value: 'first'},
        {text: 'Second Option', value: 'second'},
        {text: 'Third Option',  value: 'third'}
    ],
    autoLoad : true,
    autoDestroy : true
});

    panel.items.add(list);
    panel.items.add(stateList);
    panel.doLayout();               
    }
});

2 个答案:

答案 0 :(得分:1)

var stateList = new Ext.form.Select({
 label : 'State',
 name: 'state',
 widht: '100%',
 options: [
    {text: 'First Option',  value: 'first'},
    {text: 'Second Option', value: 'second'},
    {text: 'Third Option',  value: 'third'}
 ],
 autoLoad : true,
 listeners: {
     change:function(field,value){
       console.log(field+' '+value);
     }
 },

});

您需要像这样更改

答案 1 :(得分:0)

var stateList = new Ext.form.Select({
 label : 'State',
 name: 'state',
 widht: '100%',
 options: [
    {text: 'First Option',  value: 'first'},
    {text: 'Second Option', value: 'second'},
    {text: 'Third Option',  value: 'third'}
 ],
 autoLoad : true,
 autoDestroy : true,
 listeners= {
    blur: function(selectField, e) {
            console.log(selectField.getValue());
    }
 }

});