Ext 2-使用Widgets
使用Widgets
Widget原意为“小器件”,现指页面中UI控件
除了我们已经讨论过的核心JavaScript库,当前的Ext亦包括了一系列的最前端的JavaScirptUI组件库。文本以一个常用的widget为例子,作简单的介绍。
MessageBox
比起略为沉闷的“HelloWolrd”消息窗口,我们做少许变化,前面我们写的代码是,单击某个段落便会高亮显示,现在是单击段落,在消息窗口中显示段落内容出来。 在上面的paragraphClicked的function中,将这行代码:
Ext.get(e.target).highlight();
var paragraph = Ext.get(e.target);paragraph.highlight();Ext.MessageBox.show({ title: 'Paragraph Clicked', msg: paragraph.dom.innerHTML, width:400, buttons: Ext.MessageBox.OK, animEl: paragraph });
Ext.onReady(function() { var myData = [['Apple',29.89,0.24,0.81,'9/1 12:00am'],['Ext',83.81,0.28,0.34,'9/12 12:00am'],['Google',71.72,0.02,0.03,'10/1 12:00am'],['Microsoft',52.55,0.01,0.02,'7/4 12:00am'], ['Yahoo!',29.01,0.42,1.47,'5/22 12:00am'] ];var ds = new Ext.data.Store({proxy: new Ext.data.MemoryProxy(myData), reader: new Ext.data.ArrayReader({id: 0}, [ {name: 'company'},{name: 'price', type: 'float'},{name: 'change', type: 'float'},{name: 'pctChange', type: 'float'},{name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'} ])});ds.load();var colModel = new Ext.grid.ColumnModel([{header: "Company", width: 120, sortable: true,dataIndex: 'company'},{header: "Price", width: 90, sortable: true, dataIndex: 'price'},{header: "Change", width: 90, sortable: true, dataIndex: 'change'}, {header: "% Change", width: 90, sortable:true,dataIndex: 'pctChange'},{header: "Last Updated", width: 120, sortable: true,renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}]);var grid = new Ext.grid.Grid('grid-example', {ds: ds, cm: colModel}); grid.render();grid.getSelectionModel().selectFirstRow();});