Guide applies to: modern
A dataview renders a template for every record in a store. The items can be associated with a CSS style. You can bind to the dataview’s selection
, and listen to events.
- itemCls is applied to each item
- overItemCls is applied as you mouse over an item
selectedItemCls is applied when you select an item
Expand Code
JS Run
Ext.define('MyApp.view.Main', {
//extend: 'Ext.view.View', // classic
extend: 'Ext.dataview.DataView', // modern
itemTpl: '<img src="{image}">',
cls: 'movies',
itemCls: 'movie',
overItemCls: 'over',
selectedItemCls: 'selected',
listeners: {
itemtap: function(view, record){
// You could listen to select too, but that's only fired as the selection
// changes, so you wouldn't detect clicking on the same item twice.
Ext.toast({
html: 'You clicked on ' + record.get('movie'),
align: 't'
});
}
},
store: {
model: getModel(),
autoLoad: true
},
emptyText: 'An Internet connection is needed to load titles from iTunes.'
});
Ext.application({
name: 'MyApp',
mainView: 'MyApp.view.Main'
});
function getModel(){
Ext.define('MyApp.model.Movie', {
extend: 'Ext.data.Model',
fields: [{
name: 'id',
mapping: 'id.attributes["im:id"]'
}, {
name: 'movie',
mapping: '["im:name"].label'
}, {
name: 'image',
mapping: '["im:image"][2].label'
}],
proxy: {
type: 'jsonp',
url: 'https://itunes.apple.com/us/rss/topmovies/limit=5/json',
reader: {
type: 'json',
rootProperty: 'feed.entry'
}
}
});
return 'MyApp.model.Movie';
}