- 浏览: 183860 次
最新评论
-
adamed:
zhangwenzhuo 写道为什么this.get()会返回 ...
jQuery源码历代记5 -
zhangwenzhuo:
为什么this.get()会返回本身的呢?
jQuery源码历代记5 -
narutolby:
支持下~,哈哈~
jQuery历代记1 -
cpszy:
mark下
jQuery历代记1 -
gleams:
支持你
jQuery历代记1
原文地址:http://blog.extjs.eu/know-how/writing-a-big-application-in-ext-part-2/
Writing a Big Application in Ext (Part 2)
2. February 2009 – 14:12 Important
If you have not already done so, study Writing a Big Application in Ext (Part 1) before you read this article. It would be very hard, if not impossible, to understand concepts explained here before you fully understand the first part.
Introduction
It has been almost one year since I have published the first part of this article. I have been successfully using the concept of pre-configured classes personally to write a really big application (~150 javascript files, ~60,000 lines of code, plus server-side and css). The application is fully modularized, each class in separate file and it has proven that it can be easily developed, managed and debugged.
Unfortunately, the same has not been always true for other users, they were hitting various problems and Ext Support Team have had to handle may questions and help requests. These accumulated to the degree where the concept has been called “absolute abomination” (read absolutely hated) and it was stated that “it causes problems”.
Note: As “fast cars” do not cause accidents but “slow drivers driving fast cars” do, the concept itself cannot be a cause of the problems but its application can.
In any case, there must be some illogic if I can use the concept but others cannot.
Thus, I have looked deeper in it and I have isolated some pitfalls the users can run into on the course of development. I will also write on “dos” and “don’ts” and on when to use a pre-configured class and when not. I will not compare this concept to another application design concepts (factory functions, in-line configuration, on-demand load, or other) because 1) I do not use them and 2) I do not want to turn this article into a Linux versus Windows discussion.
It is fully up to you which application design concept you choose. However, if you do choose this one then follow the rules I’m going to lay down.
Most Common Sources of Troubles
•Dull Copy&Paste
•Extending a non-Ext.Component class
•Not calling parent methods
•initialConfig
•listeners
Dull Copy&Paste
Do you know such people? They post on a forum:
I need to drag from tree to qrid, gimme plz complete codez
And if somebody altruistic writes a fragment of “codez” for him in a sheer attempt to help the response is going to be:
Your codez don’t work. Help me plz my manager wants it working
Do you see what happened? A dull “developer” ordered a code on the forum, he’s got some, copied&pasted it to his application without a clue what the code does, maybe hasn’t even changed url that still points to your server and the result is: it doesn’t work.
Well, this is an extreme (but not so rare as you would think), nevertheless, copying&pasting without understanding of what the copied&pasted code does can lead only to frustrations.
I am not against Copy&Paste in general, it can save a lot of time and I also occasionally do it, but I am against not-understanding or mis-understanding not only of coding but also of life.
The Rule: Do Copy&Paste but always with full understanding of what the code does.
Extending a non-Ext.Component class
If an Ext class does not inherit from Ext.Component the initComponent is never called so the code you have written there is never executed. This is fragment from Ext.Component constructor:
Ext classes that do not inherit from Ext.Component do not have this.initComponent(); line in their constructors.
The Rule: Always check if the Ext class you are going to pre-configure inherits from Ext.Component. You have to use an another approach if it does not.
Not calling parent methods
It happens very often that you do not only add some methods in your extended class but that you modify existing ones. initComponent being the first example. onRender, afterLayout are other (but not only) frequently overriden methods.
These methods are already implemented in the class you are extending and its parents so if you forget the line:
// in initComponent override
YourExtension.superclass.initComponent.apply(this, arguments);
// or in onRender override
YourExtension.superclass.onRender.apply(this, arguments);
// or in afterLayout override
YourExtension.superclass.afterLayout.apply(this, arguments);your class will not work.
The Rule: Never forget to call the parent method, unless you exactly know what you are doing.
initialConfig
The constructor of Ext.Component saves the config passed to it as initialConfig:
You see what happens? The constructor saves initialConfig before initComponent is executed. Thus, all configuration you write in initComponent is not saved. I have overlooked this in first versions of my templates and examples mainly because there is only a couple of classes that refer to initialConfig and even in these classes the absence of properly saved initialConfig causes problems very rarely. These Ext classes refer to initialConfig:
•AnchorLayout
•BorderLayout
•Action
•GridPanel
•Tip
•Combo
•Form
Now, I have updated all my examples, extensions, templates and main site to include this “magic” pattern:
YourExtension.superclass.initComponent.apply(this, arguments);
The Rule: Ensure that your extension saves initialConfig.
listeners
If you try to install event handlers by setting property listeners in your config they will not work. Why? The answer lies again in the order of actions in Ext.Component constructor:
As you can see, the constructor calls its parent, that is Ext.util.Observable before initComponent. Ext.util.Observable constructor executes:
Any listeners set in initComponent are thus ignored.
There is an easy workaround. Put constructor method in your extension:
and define your listeners therein.
The Rule: Define listeners in constructor method.
Conclusion
If you decide to use my way of writing a big application then follow these rules:
1.Do Copy&Paste but always with full understanding of what the code does.
2.Always check if the Ext class you are going to pre-configure inherits from Ext.Component. You have to use an another approach if it does not.
3.Never forget to call the parent method, unless you exactly know what you are doing.
4.Ensure that your extension saves initialConfig.
5.Define listeners in constructor method.
Happy extending!
Writing a Big Application in Ext (Part 2)
2. February 2009 – 14:12 Important
If you have not already done so, study Writing a Big Application in Ext (Part 1) before you read this article. It would be very hard, if not impossible, to understand concepts explained here before you fully understand the first part.
Introduction
It has been almost one year since I have published the first part of this article. I have been successfully using the concept of pre-configured classes personally to write a really big application (~150 javascript files, ~60,000 lines of code, plus server-side and css). The application is fully modularized, each class in separate file and it has proven that it can be easily developed, managed and debugged.
Unfortunately, the same has not been always true for other users, they were hitting various problems and Ext Support Team have had to handle may questions and help requests. These accumulated to the degree where the concept has been called “absolute abomination” (read absolutely hated) and it was stated that “it causes problems”.
Note: As “fast cars” do not cause accidents but “slow drivers driving fast cars” do, the concept itself cannot be a cause of the problems but its application can.
In any case, there must be some illogic if I can use the concept but others cannot.
Thus, I have looked deeper in it and I have isolated some pitfalls the users can run into on the course of development. I will also write on “dos” and “don’ts” and on when to use a pre-configured class and when not. I will not compare this concept to another application design concepts (factory functions, in-line configuration, on-demand load, or other) because 1) I do not use them and 2) I do not want to turn this article into a Linux versus Windows discussion.
It is fully up to you which application design concept you choose. However, if you do choose this one then follow the rules I’m going to lay down.
Most Common Sources of Troubles
•Dull Copy&Paste
•Extending a non-Ext.Component class
•Not calling parent methods
•initialConfig
•listeners
Dull Copy&Paste
Do you know such people? They post on a forum:
I need to drag from tree to qrid, gimme plz complete codez
And if somebody altruistic writes a fragment of “codez” for him in a sheer attempt to help the response is going to be:
Your codez don’t work. Help me plz my manager wants it working
Do you see what happened? A dull “developer” ordered a code on the forum, he’s got some, copied&pasted it to his application without a clue what the code does, maybe hasn’t even changed url that still points to your server and the result is: it doesn’t work.
Well, this is an extreme (but not so rare as you would think), nevertheless, copying&pasting without understanding of what the copied&pasted code does can lead only to frustrations.
I am not against Copy&Paste in general, it can save a lot of time and I also occasionally do it, but I am against not-understanding or mis-understanding not only of coding but also of life.
The Rule: Do Copy&Paste but always with full understanding of what the code does.
Extending a non-Ext.Component class
If an Ext class does not inherit from Ext.Component the initComponent is never called so the code you have written there is never executed. This is fragment from Ext.Component constructor:
this.getId(); Ext.ComponentMgr.register(this); Ext.Component.superclass.constructor.call(this); if(this.baseAction){ this.baseAction.addComponent(this); } this.initComponent();
Ext classes that do not inherit from Ext.Component do not have this.initComponent(); line in their constructors.
The Rule: Always check if the Ext class you are going to pre-configure inherits from Ext.Component. You have to use an another approach if it does not.
Not calling parent methods
It happens very often that you do not only add some methods in your extended class but that you modify existing ones. initComponent being the first example. onRender, afterLayout are other (but not only) frequently overriden methods.
These methods are already implemented in the class you are extending and its parents so if you forget the line:
// in initComponent override
YourExtension.superclass.initComponent.apply(this, arguments);
// or in onRender override
YourExtension.superclass.onRender.apply(this, arguments);
// or in afterLayout override
YourExtension.superclass.afterLayout.apply(this, arguments);your class will not work.
The Rule: Never forget to call the parent method, unless you exactly know what you are doing.
initialConfig
The constructor of Ext.Component saves the config passed to it as initialConfig:
/** * This Component's initial configuration specification. Read-only. * @type Object * @property initialConfig */ this.initialConfig = config; Ext.apply(this, config); this.addEvents(/* abbreviated for clarity */); this.getId(); Ext.ComponentMgr.register(this); Ext.Component.superclass.constructor.call(this); if(this.baseAction){ this.baseAction.addComponent(this); } this.initComponent();
You see what happens? The constructor saves initialConfig before initComponent is executed. Thus, all configuration you write in initComponent is not saved. I have overlooked this in first versions of my templates and examples mainly because there is only a couple of classes that refer to initialConfig and even in these classes the absence of properly saved initialConfig causes problems very rarely. These Ext classes refer to initialConfig:
•AnchorLayout
•BorderLayout
•Action
•GridPanel
•Tip
•Combo
•Form
Now, I have updated all my examples, extensions, templates and main site to include this “magic” pattern:
// create config var config = { // put your config here }; // eo config object // apply config Ext.apply(this, Ext.apply(this.initialConfig, config)); // call parent
YourExtension.superclass.initComponent.apply(this, arguments);
The Rule: Ensure that your extension saves initialConfig.
listeners
If you try to install event handlers by setting property listeners in your config they will not work. Why? The answer lies again in the order of actions in Ext.Component constructor:
Ext.Component.superclass.constructor.call(this); if(this.baseAction){ this.baseAction.addComponent(this); } this.initComponent();
As you can see, the constructor calls its parent, that is Ext.util.Observable before initComponent. Ext.util.Observable constructor executes:
Ext.util.Observable = function(){ if(this.listeners){ this.on(this.listeners); delete this.listeners; } };
Any listeners set in initComponent are thus ignored.
There is an easy workaround. Put constructor method in your extension:
constructor:function(config) { // parent constructor call pre-processing - configure listeners here config = config || {}; config.listeners = config.listeners || {}; Ext.applyIf(config.listeners, { // add listeners config here }); // call parent constructor AnExtension.superclass.constructor.call(this, config); // parent constructor call post-processing } // eo function constructor
and define your listeners therein.
The Rule: Define listeners in constructor method.
Conclusion
If you decide to use my way of writing a big application then follow these rules:
1.Do Copy&Paste but always with full understanding of what the code does.
2.Always check if the Ext class you are going to pre-configure inherits from Ext.Component. You have to use an another approach if it does not.
3.Never forget to call the parent method, unless you exactly know what you are doing.
4.Ensure that your extension saves initialConfig.
5.Define listeners in constructor method.
Happy extending!
发表评论
-
jQuery Mobile插件开发1
2012-10-17 14:31 3630最近的项目使用jQuery Mobile开发别克手机官网 ... -
localStorage、sessionStorage用法总结
2012-10-15 17:25 88579localStorage和sessionStorage ... -
Bit This 视觉差滚动效果分析
2012-07-06 11:44 2891Bit This 是一家位于西班牙马德里的代理公司。 ... -
深入详解EXT2.3事件增加及删除源码
2012-02-23 11:06 1555先看addListener也就是Ext里面的on方法 ... -
答复: [原创]ExtJS 2.3源码分析(2012年02月21日更新)
2012-02-21 13:51 987临时详解下下面的代 ... -
JAVA验证中文正则
2012-02-20 22:03 1235public static void main(String[ ... -
HTML5 Geolocation小结
2012-02-20 17:23 1235HTML5中 Geolocation主要包 ... -
HTML5中JSON的原生支持
2012-02-20 17:22 10601、可以直接使用JSON.stringify(jsonobje ... -
JavaScript函数变换
2012-02-20 17:16 966在编写JS框架时有时会遇到编写的方法涉及复杂的操作或需要定义特 ... -
如何在MyEclipse中修改Maven本地仓库位置
2010-06-17 23:14 84571、本地需要安装Maven。这里假设安装在D:\Program ... -
目前已出版的基本Flex4书籍(是英文已出版)
2010-04-01 13:40 24261、Professional BlazeDS: Creatin ... -
JavaScript系列视频
2010-03-24 11:18 935大家好,由我和CSDN的学生大本营合作进行JavaScript ... -
Flex4正式版命名空间的变化
2010-03-24 11:03 1354与之前的FLEX3相比,在FLEX4的beta版(包括beta ... -
如何使用ExtJS构建应用系统3
2009-12-30 16:14 1391原文地址:http://blog.extjs.eu/know- ... -
如何使用ExtJS构建应用系统
2009-12-30 16:10 3035原文地址:http://blog.extjs.eu/know- ... -
ExtJS中的onRender和render
2009-12-30 16:05 7416ExtJS老大在官方论坛的一个回复,转到这里收藏下 The ... -
《数据仓库生命周期工具箱》读书笔记 1
2009-11-05 13:39 1192今天读的是这本书的第6 ... -
《数据仓库》读书笔记 4
2009-10-26 17:55 908今天开始读数据仓库的第四章,这一章讲解的是数据仓库中的粒度。 ... -
《数据仓库》读书笔记 3
2009-10-16 15:07 973这两天读了《数据仓库》第三章,这一章讲解的是设计数据仓库。 ... -
《数据仓库》读书笔记 2
2009-10-15 10:12 927读了数据仓库第2章,这 ...
相关推荐
EXTJS是一种基于JavaScript的...综上所述,EXTJS和DWR结合使用,可以构建出高度交互、用户体验良好的桌面应用系统。开发者需要对这两项技术有深入理解,才能充分利用它们的优势,打造出功能齐全、性能卓越的Web应用。
3. **参考案例研究**:网上有许多使用ExtJS构建的真实案例,通过分析这些案例,可以学到很多实战经验和技巧。 4. **参与社区讨论**:加入ExtJS的社区论坛或社交媒体群组,与其他开发者交流心得,解决遇到的问题。 ...
EXTJS是一种基于JavaScript的富客户端应用开发框架,由Sencha公司...通过熟练掌握EXTJS,开发者可以创建出具有高度交互性和用户友好性的Web应用程序,即使是在浏览器环境中,也能提供近似于桌面操作系统的使用感受。
### 使用ExtJs构建树形菜单功能详解 #### 一、引言 在现代Web应用程序开发中,树形菜单是一项常用且重要的功能。它能够帮助用户更直观地理解数据层次关系,尤其是在展示组织架构、文件系统或者任何有层级结构的...
【标题】:使用Extjs构建的简易酒店管理系统 在IT行业中,开发用户界面时经常会用到JavaScript库,其中ExtJS是一个强大的前端框架,用于构建功能丰富的、交互式的Web应用程序。本项目“使用Extjs写的简单酒店管理...
在"Extjs酒店管理系统"中,这一技术被充分利用,构建出直观且易于操作的界面。通过Extjs,开发者能够轻松创建数据驱动的网格、表单、菜单、工具栏等,极大地提高了系统的交互性和用户体验。此外,Extjs 2.0支持AJAX...
"ExtJs教学管理系统"是一个基于ExtJs框架和.Net后端技术构建的应用程序,旨在提供一套教育机构或学校使用的教学管理解决方案。此系统可能包括学生管理、课程管理、成绩管理、教师管理等多个模块,以帮助教育工作者...
ExtJS是一种基于JavaScript的开源富客户端框架,专用于构建交互式和桌面级的Web应用程序。在《ExtJS Web应用程序开发指南(第2版)》中,开发者可以深入了解如何利用这个强大的框架来创建功能丰富的Web应用。这本书...
ExtJS物流管理系统是一款基于Web的物流管理解决方案,利用先进的前端技术ExtJS和后端框架SSH(Struts2、Spring、Hibernate)实现。该系统旨在提供高效、便捷的物流业务流程管理,包括货物跟踪、订单处理、仓储管理等...
ExtJs3是一个强大的JavaScript框架,主要用于构建富客户端的Web应用程序。...通过分析和研究这个系统,开发者可以掌握如何使用ExtJs3构建复杂且功能丰富的前端应用,并为实际项目提供有价值的参考。
ExtJS 文件管理系统是一款基于 ExtJS 框架构建的高效、功能丰富的文件管理应用程序。它提供了用户友好的界面,使得用户能够轻松地进行文件的压缩、解压以及搜索操作。ExtJS 是 Sencha 公司推出的一个强大的 ...
**JSP与EXTJS在EFS管理系统的应用** 在IT领域,JSP(JavaServer Pages)和EXTJS是两种常用的技术,它们在构建Web应用程序时发挥着重要作用。本项目"jsp extjs Efs管理系统"结合了这两者的优点,提供了一个完整的、...
本教程主要讲述如何利用Struts2,Hibernate,Spring架构来构建企业级应用解决方案,前台用ExtJS展现主要分为两部分完成 第一部分介绍电子商业汇票系统业务。 第二部分,将实际应用(某银行-电子商业汇票系统)为例,...
EXTJS是一种基于JavaScript的开源富客户端框架,专用于构建企业级Web应用程序。它提供了一套完整的组件库,包括数据网格、表单、图表等,使得开发者可以构建出交互性强、用户体验良好的网页应用。EXTJS信息系统显然...
本系统采用EXTJS进行前端开发,EXTJS是一款强大的JavaScript组件库,以其丰富的UI组件和数据绑定机制,为开发高质量的Web应用提供了便利。 EXTJS的核心特性包括: 1. **组件化设计**:EXTJS以组件为中心,提供了...
EXTJS是一种基于JavaScript的开源富客户端框架,专用于构建交互式、数据驱动的Web应用程序。在"EXTJS图书管理系统页面(JAVA)"这个项目中,我们主要关注的是EXTJS在图书管理系统中的应用,以及它与Java后端的交互。...
本文将详细介绍一个使用ExtJS开发的图书管理系统,该系统同时结合了Spring和iBATIS作为其核心架构组件。 首先,ExtJS是一个流行的JavaScript库,用于构建桌面级的Web应用程序。它提供了丰富的UI组件,如表格、窗口...
ExtJS是一个强大的JavaScript库,专为构建富客户端应用程序而设计。在投票系统中,它用于创建交互式和动态的用户界面: 1. **组件模型**:ExtJS提供了丰富的组件库,如表格、面板、窗口、按钮等,方便快速构建复杂...
本文将深入探讨一款名为"Extjs版酒店管理系统"的软件,它利用Visual Studio 2005(VS2005)、SQL Server 2000以及Extjs 2.0技术构建,旨在为酒店业提供全面、便捷的信息化解决方案。 首先,让我们关注该系统的开发...
ExtJS是一种强大的JavaScript库,专用于构建富互联网应用程序(RIA)。它提供了丰富的组件库,包括数据网格、图表、表单、导航视图等,能够帮助开发者构建功能丰富的、交互性强的用户界面。在这个基于ExtJS的通用...