`
wanghaisheng
  • 浏览: 89683 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

extjs4 tree 学习

阅读更多

最近在做一个项目,做到部门管理用到了extjs4的树形展示,搞得是焦头烂额,碰到了很多问题,而且firefox只报些不知所谓的异常,根本没法调试。今天终于解决了

网上再好的教程也没官方的guide好,来得精辟,网上的教程全部大同小异,全没讲到重点,extjs4下的guides 地址为{webapp}/docs/index.html#!/guide/tree  ,其中{webapp}为你extjs文档在服务器的应用名,这篇文章真的很经典,不像网上那些教程,只是本人英文不啥的,花了半天才看懂皮毛

 

The Tree Panel Component is one of the most versatile Components in Ext JS and is an excellent tool for displaying heirarchical data in an application. Tree Panel extends from the same class as Grid Panel, so all of the benefits of Grid Panels - features, extensions, and plugins can also be used on Tree Panels. Things like columns, column resizing, dragging and dropping, renderers, sorting and filtering can be expected to work similarly for both components.

 

大意是:Tree Panel 组件是Ext Js的分层应用中最多功能和最优秀组件之一,Tree Panel 继承和Grid Panel继承自同一个类,所以它拥有Grid Panels的所有特性——功能,扩展性,以及插件,这些都能在Tree Panels中使用。比如列模型,列的伸缩,拖拽,渲染,排序和过滤,这些功能都能在两个控件中使用

 

In the above examples we set a couple of different properties on tree nodes. But what are nodes exactly? As mentioned before, the Tree Panel is bound to a TreeStore. A Store in Ext JS manages a collection of Model instances. Tree nodes are simply Model instances that are decorated with a NodeInterface. Decorating a Model with a NodeInterface gives the Model the fields, methods and properties that are required for it to be used in a tree. 

 

大意是:在下面的例子中我们为tree nodes设置了几个属性,但是如何准确地定义nodes?就像以前提到的,Tree Panel 绑定到TreeStore,在Ext Js 中Store绑定着Model实例的集合。Tree nodes 仅仅只是一些被NodeInterface封装过的Model的实例的集合,利用NodeInterface给Model注入一些在tree中需要用到的fields,methods和properties

 

 

接下来的这段非常重要,相信很多人在使用extjs4 Tree Panel 中的appendChild()时,都会碰到“update info is not a function”(如果没碰到,你真的很幸运),我就是不幸中的一位,baidu,google了一整天,偶尔碰到有人提出这样的问题,却没一人回答,呵呵,大牛们,你们不知道我们这些自学的人的苦处吗,知道的话就不能点拨一下吗?

The first and most important thing to understand when working with tree data is how the NodeInterface class' fields work. Every node in a Tree is simply a  Model instance decorated with the NodeInterface's fields and methods. Assume for a moment that an application has a Model called Person. A Person only has two fields - id and name:

大意是:当使用tree data时,首先也是最重要的事情就是理解NodeInterface是如何工作的,Tree 中的每一个node仅仅只是被NodeInterface封装过的Model的实例,NodeInterface向其中注入了fields,methods。假设某个时候,一个应用拥有一个Model名为Person,Person只有两个fields——id和name

 

Ext.define('Person', {
    extend: 'Ext.data.Model',
    fields: [
        { name: 'id', type: 'int' },
        { name: 'name', type: 'string' }
    ]
});

 

 At this point Person is just a plain vanilla Model. If an instance is created, it can easily be verified that it only has two fields by looking at its fields collection

大意是:在此处Person只是一个平常的Model,如果创建一个实例,很容易就能证明它只包含2个field

 

console.log(Person.prototype.fields.getCount()); // outputs '2'
 

 

When the Person model is used in a TreeStore, something interesting happens. Notice the field count now:

大意是:当Person model在TreeStore中使用时,一些有趣的事情发生了,现在注意field的数量:

 

var store = Ext.create('Ext.data.TreeStore', {
    model: 'Person',
    root: {
        name: 'Phil'
    }
});

console.log(Person.prototype.fields.getCount()); // outputs '24'

 

 The Person model's prototype got 22 extra fields added to it just by using it in a TreeStore. All of these extra fields are defined on the NodeInterface class and are added to the Model's prototype the first time an instance of that Model is used in a TreeStore (by setting it as the root node).

大意是:当被应用在TreeStore的时候,Person model的prototype得到了22个额外的fields,所有的这些额外添加的属性都是在NodeInterface class中定义的,而且是在Store中的Model实例第一次被使用的时候被添加进来的(被设置为Tree r的root node)

上面说到的‘updateinfo is not a function’就是这个造成的,相信那些没碰到这个问题的都只是在一个js文件中玩玩小demo,从来就没有按照Ext Js4的MVC分层来定义类,所以他们能一口所通过。

如果是按照MVC架构分文件定义Model的话,当你var record = Ext.create(modelName)时,此时并不会为你的Model封装进NodeInterface的field,只有利用tree.store.getProxy().getModel()得到的Model才是真正拥有NodeInterface 的fields的Model,此时Ext.create(model)才会有updateinfo方法

 

 

NodeInterface Fields are Reserved Names

It is important to note that all of the above field names should be treated as "reserved" names. For example, it is not allowed to have a field called "parentId" in a Model, if that Model is intended to be used in a Tree, since the Model's field will override the NodeInterface field. The exception to this rule is when there is a legitimate need to override the persistence of a field.

大意是:NodeInterface中的Fields都是保留Names,比如说,在Model中不能存在一个field名为parentId,当我们在Tree中定义的Model重写了NodeInterface中的field,我们应该为这个合理需求重写field中的persistence

Most of NodeInterface's fields default to persist: false. This means they are non-persistent fields by default,Non-persistent fields will not be saved via the Proxy when calling the TreeStore's sync method or calling save() on the Model.

绝大部分的NodeInterface的fields的persist默认值为false,这意味着当你调用TreeStore的sync方法或调用Model的save方法时,它们并不通过Proxy保存

水平不行,就不乱翻译了,这些都是重点

另外,在tree中定义store时,store:Ext.create('storeName'),而在controller中又定义了store,则Ext Js会向服务器发送两次加载此store文件的请求,

如firefox提示:'name is undefined',则多半是你的alias名错误

 

分享到:
评论

相关推荐

    extjs tree 学习资料

    extjs tree 学习资料extjs tree 学习资料extjs tree 学习资料extjs tree 学习资料

    动态加载extjs tree

    最近在学习extjs tree,有两个不错的例子,希望对需要的朋友有所帮助!

    ExtJS4中文教程2 开发笔记 chm

    Extjs4 带复选框的树(Checkbox tree) Extjs4 新的布局方式 Extjs4 锁定表头(Locking Grid)功能 Extjs4.0 MVC实例 Extjs4.0动态填充combobox数据 Extjs4中up()和down()的用法 ExtJS4学习笔记(一)---window的创建 ...

    extjs4.0的高级组件tree加grid整合案例上.part2

    学习extjs资料,tree合成grid,很不错的视频文件,值得收藏

    ExtJS4 doc文档

    ExtJs学习、编程利器【data,proxy,grid,tree,toolbar,tree】

    extjs4 项目例子

    这个项目里面包含了本人从开始初学EXTJS4的全部事例:grid、tree、chart图表、文件上传、mvc、还有用户信息注册。里面的一些难点、要点都加了注释,还有一个file.txt文件是本人的小小总结,还没完整。我也是一个第一...

    Extjs之tree

    ExtJs tree开发小实例,有兴趣的朋友可以下载来学习一下。大家共同进步

    extjs4.0的高级组件tree加grid整合案例上.part3

    学习extjs资料,tree合成grid,很不错的视频文件,值得收藏

    Extjs tree的简单小例子

    最近项目需要extjs的树,学习了一下,写了个小例子。 呃……虽然比较简单~但是还是花了半天才写出来~ 包、数据库的操作就没贴了。

    extjs实例与学习资料

    因为前段时间有两个专案要用到extjs技术,所以自己学了一段时间,在专案才发现extjs的强大,无论对于开发者还是使用者他都是一场视觉盛宴,这里有我从学习开始做的一些笔记和例子也有自己收集的学习资料,里面包括...

    extjs4.0的高级组件tree加grid整合案例上.part1

    学习extjs资料,tree合成grid,很不错的视频文件,值得收藏

    ExtJS(ajax框架) 4.2.1

    使用MVC,开发团队只需要学习一种架构就能理解任何ExtJS 4的应用。 SDK工具:正在测试beta版的Sencha SDK工具,在第一版本中包括了优化工具、生成器和slicer工具。这些工具可让你优化Javascript程序,以确保主题能...

    extjs目录树编辑

    extjs目录树编辑对目录增删改查学习extjs的工具类

    ExtJS框架学习综合项目

    这是对ExtJS学习的一个小总结,做成了一个可运行的小项目,包括了gird,form,tree等ExtJS组件的使用,以及ExtJS的布局管理。部分案例通过ExtJS页面直接操作后台数据,还包括了poi,jxl生成Excel表格的操作,以及grid在...

    基于s2sh+Extjs+dwr OA系统带全部JAR

    用的东西比较杂,主要为了学习一下知识呵呵: ssh2、dwr、jquery、extjs、jquery weekcalendar、jfreechart、jasperreport 联系人实现了拖动实现好友分组。可以把grid直接拖到tree,不同于其他的例子,拖动grid后会...

    extjs学习案例, 例子有 panel ,widow,tree,grid,form, store……

    对于初学者来说是一份很好的资料, 对于已学者来说,可以得到一定的提高……

    ExtJS 4.2 实例

    这是本人在学习ExtJS 4.2 过程中做的一个小实例,包含了一些基础的功能: Tree/Grid/分页查询,滚动查询等. 与数据库的连接以及表结构在附件中的说明文档中有写.

    JSP实现树型结构TREE

    本例是用JSP+EXTJS+JSON+MYQL实现的树型结构,例子结构清晰,便于学习。

    ExtJSWeb应用程序开发指南(第2版)

    1.3 是否真的需要学习ExtJS 1.4 ExtJS4.0新特性 1.5 ExtJSUI组件基础 1.6 了解一下类似技术 1.7 本章小结 第2章 开始ExtJS之旅 2.1 认识ExtJS的开发包 2.2 也从Helloworld开始 2.3 ExtJS中的基本概念 2.4 ...

    ssh2 extjs oa

    用的东西比较杂,主要为了学习一下知识呵呵: ssh2、dwr、jquery、extjs、jquery weekcalendar、jfreechart、jasperreport 联系人实现了拖动实现好友分组。可以把grid直接拖到tree,不同于其他的例子,拖动grid后会在...

Global site tag (gtag.js) - Google Analytics