简体   繁体   English

组织ExtJS项目的最佳方式

[英]Best Way to Organize an ExtJS Project

I've just started developing an ExtJS application that I plan to support with a very lightweight JSON PHP service. 我刚开始开发一个ExtJS应用程序,我打算用非常轻量级的JSON PHP服务来支持它。 Other than that, it will be standalone. 除此之外,它将是独立的。 My question is, what is the best way to organize the files and classes that will inevitably come into existence? 我的问题是,组织不可避免地存在的文件和类的最佳方法是什么? Anyone have any experience with large ExtJS projects (several thousand lines). 任何人都有大型ExtJS项目的经验(数千行)。

I would start here http://blog.extjs.eu/know-how/writing-a-big-application-in-ext/ 我会从这里开始http://blog.extjs.eu/know-how/writing-a-big-application-in-ext/

This site gives a good introductory overview of how to structure your application. 该站点提供了有关如何构建应用程序的良好介绍性概述。

We are currently using these ideas in two of our ASP.NET MVC / ExtJS applications. 我们目前在两个ASP.NET MVC / ExtJS应用程序中使用这些想法。

I suggest users are willing to wait for an application to load, so we typically load all of JS during initial app startup. 我建议用户愿意等待加载应用程序,因此我们通常在初始应用程序启动期间加载所有JS。 I suggest loading and eval'ing JS files as needed is unnecessary - especially when all JS will be minified before deployment to production. 我建议根据需要加载和评估JS文件是不必要的 - 尤其是在部署到生产之前将所有JS缩小的时候。

I suggest namepsaces, one class per file, and a well-defined and well-documented class hierarchy. 我建议使用namepsaces,每个文件一个类,以及定义明确且记录良好的类层次结构。

While developing your application your file and folder structure shouldn't really matter as you're probably going to want to minimize the release code and stick it in a single JS file when you're done. 在开发应用程序时,您的文件和文件夹结构应该不重要,因为您可能希望最小化发布代码并在完成后将其粘贴到单个JS文件中。 An automated handler or build script is probably going to be the best bet for this (see http://extjs.com/forum/showthread.php?t=44158 ). 自动处理程序或构建脚本可能是最好的选择(参见http://extjs.com/forum/showthread.php?t=44158 )。

That said, I've read somewhere on the ExtJS forums that a single file per class is advisable, and I can attest to that from my own experience. 也就是说,我在ExtJS论坛的某个地方读过,每个类的单个文件是可取的,我可以根据自己的经验证明这一点。

When starting new big project, I decided to make it modular. 在开始新的大项目时,我决定将其模块化。 Usually, in big projects not all modules are used by a particular user, so I load them on demand. 通常,在大项目中,并非所有模块都由特定用户使用,因此我按需加载它们。 Fe, if a project would have 50+ modules, the big probability is that user is working only with 10-. Fe,如果一个项目有50多个模块,很可能是用户只使用10-。

Such architecture lets you to have the initial code relatively small. 这种架构使您可以使初始代码相对较小。

Modules are stored on the server and loaded by AJAX call, eval'uating the responseText in AJAX callback. 模块存储在服务器上并通过AJAX调用加载,在AJAX回调中评估responseText。 The only issue with this, you must keep track on module dependencies, which could be stored inside modules as well. 对此唯一的问题是,您必须跟踪模块依赖性,这些依赖性也可以存储在模块中。 I have a class called Module, and I check every new module instance for existance within the task. 我有一个名为Module的类,我检查每个新模块实例是否存在于任务中。 If it doesn't yet exist, I load it from the server. 如果它还不存在,我从服务器加载它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM