Ext JS 4 笔记1

ExtJS4 引入了现在灰常流行的前端MVC。这在原本的3.3.1里面是没有的。

原先项目里为了实现相对的MVC,自己写了一个controller和model ,收集并且保持JS端的数据。

所以呢,这时候的文档结构就完全不一样了。原本的结构更像是传统 C# winform ,逻辑卸载页面的cs文件里。只有对于数据收集和数据保持才会放在C和M上,逻辑操作都是直接在V上写的。

不过前端MVC也是一个趋势,怎么说C#的webform 也已经被淘汰了,人家微软都出到 asp.net MVC3了。


增加了几个类:Ext.app.Application & Ext.app.Controller & Ext.app.EventBus

Ext.app.EventBus 就像是一个全局的MessageBus,文档里是说,NOTE This is a private utility class for internal use by the framework. Don't rely on its existence.  一般不建议使用的东西,都是我们可以着重研究的地方。以后如果需要全局MessageBus的话,我们为何不直接放到这个类里面呢?

Ext.app.Application 

 Represents an Ext JS 4 application, which is typically a single page app using a Viewport. A typical Ext.app.Applicationmight look like this:

Ext.application({
    name: 'MyApp',
    launch: function() {
        Ext.create('Ext.container.Viewport', {
            items: {
                html: 'My App'
            }
        });
    }
});

 对于Ext4来说,他认为,一个典型的使用Ext框架的应用,应该是一个RIA的,也就是说,用AJAX在一个页面里流转的。所以,他认为,你这个app应该使用了Viewport,上面这段代码定义了一些全局的变量,首先创建了'MyApp'这个类,包括他的所有需要的M、V和C。也就是说创建一个全局的namespace,不用像3里面那样到处需要长名字的namespace,需要定义Ext.ns();,为了避免长名字还不得不定义许多局部的短名变量。

当然我们可以更加符合MVC模式一些。

Ext.application({
    name: 'Blog',
    models: ['Post', 'Comment'],
    controllers: ['Posts', 'Comments'],

    launch: function() {
        ...
    }

}); 

这里只有 models 和 controllers 因为 views 应该是通过 controllers 来控制管理的。

扯出去点,在 C 里面定义 V :

Ext.define('MyApp.controller.Posts', {
    extend: 'Ext.app.Controller',
    views: ['posts.List', 'posts.Edit'],

    //the rest of the Controller here

}); 

看到这里,觉得,Ext 是借鉴了 asp.net MVC 的很多东西。

Because we told our Application about our Models and Controllers, and our Controllers about their Views, Ext JS will automatically load all of our app files for us. This means we don't have to manually add script tags into our html files whenever we add a new class, but more importantly it enables us to create a minimized build of our entire application using the Ext JS 4 SDK Tools.

看到这句话的时候我整个人都斯巴达了,尼玛,Sencha 又要推 Ext JS 4 SDK …… 估计也是和 Designer 一样坑爹的东西。扯开点说,他们家的工具,我觉得还是不要使用了,Designer 也好,这个 SDK 也罢。bug 太多。不靠谱的,其实本身用这个框架就有争议,又要回到上一篇的开始了 ……

看HK的人做的 Ext JS 3 to Ext JS 4 的upgrade的study,真想掐死他。

我还是坚持认为,如果要做upgrade,就推翻重新做。很多V上的逻辑本来就应该抽出来放在C,他们从来没人想过 architecture 上的东西。

最后,还是没忍住抱怨几句。

 

 

 

 

---0101-0101-01-0111-0110-110-10011-------

如果,人生可以编码 …… 

原文地址:https://www.cnblogs.com/liyinkan/p/2293433.html