ExtJS的資料模型與資料處理結構主要元件有三:
- Model - 負責定義描述資料結構,變數名稱與資料型態{auto,string,int,float,date,bool}.
- Proxy - 負責描述與後端Server Side溝通方式{ajax,json,direct}與對應url.
- Store - 負責Model集合資料處理{sort/filter/groupping}.
Ext.define('NewClass', { constructor: function() { throw new Error('[' + Ext.getDisplayName(arguments.callee) + '] constructor Error'); return this; }});var A1 = Ext.create('NewClass', 'A1');
Ext.ns('My.cool'); // ns是namspace的別名 var MyWindow = Ext.extend(Object, { ... });My.cool.Window = Ext.extend(Ext.Window, { ... }); // My.cool需先定義好Ext.define(className, members, onClassCreated);Ext.define(className, { extend: parentClassName, ...});Ext.define('CanPlayGuitar', { playGuitar: function() { alert("F#...G...D...A"); }});Ext.define('CanSing', { sing: function() { alert("I'm on the highway to hell...") }});Ext.define('CoolPerson', { extend: 'Person', mixins: { canPlayGuitar: 'CanPlayGuitar', canSing: 'CanSing' }, sing: function() { this.playGuitar(); }});var me = new CoolPerson("Jacky");me.sing(); // alert("I'm on the highway to hell...");Ext.define('Computer', { statics: { instanceCount: 0, factory: function(brand) { // 'this' in static methods refer to the class itself return new this({brand: brand}); } }, config: { brand: null }, constructor: function(config) { this.initConfig(config); // the 'self' property of an instance refers to its class this.self.instanceCount ++; return this; }});var dellComputer = Computer.factory('Dell');Ext.define('My.own.Window', { /** @readonly */ isWindow: true, config: { title: 'Title Here', bottomBar: { enabled: true, height: 50, resizable: false } }, constructor: function(config) { this.initConfig(config); return this; }, applyTitle: function(title) { if (!Ext.isString(title) || title.length === 0) { alert('title沒有定義'); } else { return title; } }, applyBottomBar: function(bottomBar) { if (bottomBar && bottomBar.enabled) { if (!this.bottomBar) { return Ext.create('My.own.WindowBottomBar', bottomBar); } else { this.bottomBar.setConfig(bottomBar); } } }});
var myWindow = Ext.create('My.own.Window', { title: 'Hello World',
bottomBar: {
height: 60
}
});
alert(myWindow.getTitle()); // alerts "Hello World"myWindow.setTitle('測試TITLE');alert(myWindow.getTitle()); // alerts "測試TITLE"myWindow.setTitle(null); // alerts "title沒有定義"myWindow.setBottomBar({ height: 100 }); // height=100
MyCompany.useful_util.Debug_Toolbar (X) - 包含特殊符號MyCompany.util.Base64MyCompany.data.CoolProxyMyCompany.form.action.AutoLoad
Ext.data.JsonProxy
Ext.data.JSONProxy (X) - JSON未遵循Camel Casting
MyCompany.util.HtmlParser
MyCompary.parser.HTMLParser (X) - HTML未遵循Camel Casting
MyCompany.server.Http
MyCompany.server.HTTP (X) - HTTP未遵循Camel Casting| :Top-Level namespace | |
| :Class name |
Ext.util.Observable -> web/ext/src/Ext/util/Observable.jsExt.form.action.Submit -> web/ext/src/Ext/form/action/Submit.jsMyCompany.chart.axis.Numeric -> web/ext/src/MyCompany/chart/axis/Numeric.jsExt.MessageBox.YES = "Yes"Ext.MessageBox.NO = "No"MyCompany.alien.Math.PI = "4.13"- appname // app目錄 - app // 自訂classes - namespace - Class1.js - Class2.js - ... - extjs // extsdk位置 - resources // ext所需之css/image等 - css - images - ... - app.js // 此系統的js - index.html // 網頁進入點Ext.application({ name: 'HelloExt', launch: function () { Ext.create('Ext.container.Viewport', { layout: 'fit', items: [ { title: 'Hello Ext', html: 'Hello! Welcome to Ext JS.' } ] }); }});sencha create jsb -a index.htm -p app.jsb3sencha build -p app.jsb3 -d .