富客戶端程序設計實例 - 視圖層(Ext JS) - Ext MVC Application Architecture 簡介
Ext MVC Application Architecture 是ExtJS4.0開始引入的一種全新的開發模式。Ext本身作為一種視圖層存在,但因為其開發復雜性為初學者所詬病。在ExtJS3.0時代Ext與后臺交互需要程序員自己去實現,實現的方式各種各樣,給后來人維護造成了很大不便。原引Sencha Docs的原始描述是這樣的: (http://docs.sencha.com/extjs/4.2.1/#!/guide/application_architecture)
Large client side applications have always been hard to write, hard to organize and hard to maintain. They tend to quickly grow out of control as you add more functionality and developers to a project. Ext JS 4 comes with a new application architecture that not only organizes your code but reduces the amount you have to write.
Our application architecture follows an MVC-like pattern with Models and Controllers being introduced for the first time. There are many MVC architectures, most of which are slightly different from one another. Here's how we define ours:
Model is a collection of fields and their data (e.g. a User model with username and password fields). Models know how to persist themselves through the data package, and can be linked to other models through associations. Models work a lot like the Ext JS 3 Record class, and are normally used with Stores to present data into grids and other components
View is any type of component - grids, trees and panels are all views.
Controllers are special places to put all of the code that makes your app work - whether that's rendering views, instantiating Models, or any other app logic.

【圖:FrameModel項目前臺組織結構】 </div>
</span>
翻譯大概就是:富客戶端程序總是很難寫,很難組織以及后期維護很困難。隨著項目功能的快速增長,當開發人員在一個項目中添加更多的功能的時候,項目越來月難以控制。Ext JS4.0推出以后,隨之而來的是一種新的應用程序結構。Ext JS 4的新結構不僅能組織你視圖層的代碼結構,而且還在此基礎上顯著減少你代碼的編寫量。
在4.0開始從結構上開始分層,劃分成3層:Model(Store)、View 和 Controller。Store作用相當于數據庫的某一個表;Model相當于Java中的某一個Entity(實體類或領域對象模型)。Ext.grid.Panel表中每一行的記錄就相當于一個Entity對象。Model一般都會被引入到Store中。應當注意到“app”這個文件夾,當瀏覽器加載項目JS腳本的時候,首先會進入到app文件夾下,然后去尋找對應的controller、model、store 和 view這四個文件夾,他們是ExtJS核心加載的“依據關鍵字”。也就是說連同app在內的這五個文件夾是固定要添加在項目中的。
本文由用戶 Yangcl 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!