标签:
原文地址:http://docs.sencha.com/extjs/4.0.7/#!/guide/mvc_pt2
【翻译 by 明明如月 QQ 605283073 本章节配套项目代码将在第3节给出】
上一节:Ext JS 4 架构你的应用 第1节 (官方文档翻译)
Ext.application({ name: 'Panda', autoCreateViewport: true, launch: function() { // This is fired as soon as the page is ready } });
Ext.define('Panda.view.NewStation', { extend: 'Ext.form.field.ComboBox', alias: 'widget.newstation', store: 'SearchResults', ... more configuration ... });
Ext.define('Panda.view.SongControls', { extend: 'Ext.Container', alias: 'widget.songcontrols', ... more configuration ... });
Ext.define('Panda.view.StationsList', { extend: 'Ext.grid.Panel', alias: 'widget.stationslist', store: 'Stations', ... more configuration ... });
Ext.define('Panda.view.RecentlyPlayedScroller', { extend: 'Ext.view.View', alias: 'widget.recentlyplayedscroller', itemTpl: '<div></div>', store: 'RecentSongs', ... more configuration ... });
Ext.define('Panda.view.SongInfo', { extend: 'Ext.panel.Panel', alias: 'widget.songinfo', tpl: '<h1>About </h1><p></p>', ... more configuration ... });
{ 'success': true, 'results': [ { 'name': 'Blues At Sunrise (Live)', 'artist': 'Stevie Ray Vaughan', 'album': 'Blues At Sunrise', 'description': 'Description for Stevie', 'played_date': '1', 'station': 1 }, ... ] }
{ 'success': true, 'results': [ {'id': 1, 'played_date': 4, 'name': 'Led Zeppelin'}, {'id': 2, 'played_date': 3, 'name': 'The Rolling Stones'}, {'id': 3, 'played_date': 2, 'name': 'Daft Punk'} ] }
{ 'success': true, 'results': [ {'id': 1, 'name': 'Led Zeppelin'}, {'id': 2, 'name': 'The Rolling Stones'}, {'id': 3, 'name': 'Daft Punk'}, {'id': 4, 'name': 'John Mayer'}, {'id': 5, 'name': 'Pete Philly & Perquisite'}, {'id': 6, 'name': 'Black Star'}, {'id': 7, 'name': 'Macy Gray'} ] }
Ext.define('Panda.model.Song', { extend: 'Ext.data.Model', fields: ['id', 'name', 'artist', 'album', 'played_date', 'station'], proxy: { type: 'ajax', url: 'data/recentsongs.json', reader: { type: 'json', root: 'results' } } });
Ext.define('Panda.model.Station', { extend: 'Ext.data.Model', fields: ['id', 'name', 'played_date'], proxy: { type: 'ajax', url: 'data/stations.json', reader: { type: 'json', root: 'results' } } });
Ext.define('Panda.store.SearchResults', { extend: 'Ext.data.Store', requires: 'Panda.model.Station', model: 'Panda.model.Station', // Overriding the model's default proxy proxy: { type: 'ajax', url: 'data/searchresults.json', reader: { type: 'json', root: 'results' } } });
Ext.define('Panda.store.Stations', { extend: 'Ext.data.Store', requires: 'Panda.model.Station', model: 'Panda.model.Station' });
Ext.define('Panda.store.RecentSongs', { extend: 'Ext.data.Store', model: 'Panda.model.Song', // Make sure to require your model if you are // not using Ext JS 4.0.5 requires: 'Panda.model.Song' });
Ext.application({ ... models: ['Station', 'Song'], stores: ['Stations', 'RecentSongs', 'SearchResults'] ... })
Ext.define('Panda.view.Viewport', { extend: 'Ext.container.Viewport',
requires: [ 'Panda.view.NewStation', 'Panda.view.SongControls', 'Panda.view.StationsList', 'Panda.view.RecentlyPlayedScroller', 'Panda.view.SongInfo' ],
layout: 'fit', initComponent: function() { this.items = { xtype: 'panel', dockedItems: [{ dock: 'top', xtype: 'toolbar', height: 80, items: [{ xtype: 'newstation', width: 150 }, { xtype: 'songcontrols', height: 70, flex: 1 }, { xtype: 'component', html: 'Panda<br>Internet Radio' }] }], layout: { type: 'hbox', align: 'stretch' }, items: [{ width: 250, xtype: 'panel', layout: { type: 'vbox', align: 'stretch' }, items: [{ xtype: 'stationslist', flex: 1 }, { html: 'Ad', height: 250, xtype: 'panel' }] }, { xtype: 'container', flex: 1, layout: { type: 'vbox', align: 'stretch' }, items: [{ xtype: 'recentlyplayedscroller', height: 250 }, { xtype: 'songinfo', flex: 1 }] }] }; this.callParent(); } });
Ext.define('Panda.controller.Station', { extend: 'Ext.app.Controller', init: function() { ... }, ... });
Ext.define('Panda.controller.Song', { extend: 'Ext.app.Controller', init: function() { ... }, ... });
someAction: function() { var controller = this.getController('AnotherController'); // Remember to call the init method manually controller.init(); }
Ext.application({ ... controllers: ['Station', 'Song'] });
... init: function() { this.control({ 'stationslist': { selectionchange: this.onStationSelect }, 'newstation': { select: this.onNewStationSelect } }); } ...
... init: function() { this.control({ 'recentlyplayedscroller': { selectionchange: this.onSongSelect } }); this.application.on({ stationstart: this.onStationStart, scope: this }); } ...
.. onStationSelect: function(selModel, selection) { this.application.fireEvent('stationstart', selection[0]); } ...
标签:
原文地址:http://blog.csdn.net/w605283073/article/details/51479222