2011年11月10日 星期四

Sencha Touch Coding (1) - Data Store and List

1. set up a list which loaded with data from a data store

poll.courses = new Ext.List({
store: poll.stores,
itemTpl: new Ext.XTemplate(
'<tpl for=".">',
'{courseCode}',
'</tpl>'    
),
allowDeselect:false,
singleSelect:true,
}


2.  add itemtap listener to poll.courses to get user selected item
itemtap: function(view, index, item, e){

console.log("you tap " + view.getStore().getAt(index).get('courseCode'));
}

view.getStore().getAt(index) return the selected item of data model type. here will be poll.stores 's data model, which is defined as:

Ext.regModel('Pollings', {
fields: [ 
        {name: 'courseCode', type:'string'},
]
});

沒有留言:

張貼留言