Ext JS 4 笔记0

需要研究从Ext JS 3.3.1 如何安全升级到 Ext JS 4.0

在Sencha的论坛上滚了几圈,没什么特别好的想法,抱怨声比较多。对于那个死气沉沉的论坛也正常。

我一直对当初选择 Ext 很有 concern。 不过都已经项目起了,改不了了。在项目开的时候,竟然没有人研究过 JS 究竟该怎么写,甚至没人知道怎么做 web application,现在处于这个尴尬境地也是正常。没有人想过如何减少Server Request,没有想过如何在 JS MVC。说实话,我自己也不怎么知道,不过至少我再看,我知道有 backbone,我知道有 mootools。扯远了扯远了。

着手 Ext JS 4.0

看文档,看别人的笔记,第一个吸引我的点,非常给力:Ext.require  和  Ext.create

 

requireString/String[] expressions, [Function fn], [Object scope], [String/String[] excludes] )

Loads all classes by the given names and all their direct dependencies; optionally executes the given callback function when finishes, within the optional scope.

Ext.require is alias for Ext.Loader.require for convenience.

Parameters

  • expressions : String/String[]

    Can either be a string or an array of string

  • fn : Function (optional)

    The callback function

  • scope : Object (optional)

    The execution scope (this) of the callback function

  • excludes : String/String[] (optional)

    Classes to be excluded, useful when being used with expressions

-----------------------------------------------------------------------------------------------------

 

createString name, Object... args ) : Object

Instantiate a class by either full name, alias or alternate name.

If Ext.Loader is enabled and the class has not been defined yet, it will attempt to load the class via synchronous loading.

For example, all these three lines return the same result:

// alias
 var window = Ext.ClassManager.instantiate('widget.window', { width: 600, height: 800, ... }); 

// alternate name
 var window = Ext.ClassManager.instantiate('Ext.Window', { width: 600, height: 800, ... });

// full class name
 var window = Ext.ClassManager.instantiate('Ext.window.Window', { width: 600, height: 800, ... });

Ext.create is alias for Ext.ClassManager.instantiate.

Parameters

  • name : String
  • args : Object...

    Additional arguments after the name will be passed to the class' constructor.

Returns

 

终于可以只是Load自己想要的类了。果然4给在performance上的优化,很下功夫。

不过对于项目没什么好处,因为那些class都需要被load的,那么复杂一个系统,我无法确定哪些类需要,哪些类不需要。对于我而言,依旧是一个loading的等待图标,直到所有class和cache加载完毕。

例子中 Ext.Window 网上有说需要改成 Ext.window.Window 否则在某些浏览器里无法显示,这是Ext的bug吧。 

posted on 2011-12-16 18:12  Yinkan  阅读(604)  评论(0编辑  收藏  举报

导航