`
wanghaisheng
  • 浏览: 90971 次
  • 性别: 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 ajax tree(js动态树,无需递归)

    通过查看和学习这个例子,你可以了解如何在实际项目中实现ExtJS AJAX树。 值得注意的是,ExtJS提供了一种灵活的API,允许开发者自定义节点的渲染方式、扩展节点操作以及与其他组件交互。例如,可以添加右键菜单、...

    extjs tree 学习资料

    这个压缩包“extjs tree 学习资料”显然是为那些希望深入理解并掌握ExtJS Tree组件的开发者准备的。让我们详细探讨一下ExtJS Tree的相关知识点。 1. **ExtJS Tree的基础概念** - **节点(Nodes)**:Tree的核心是...

    extjs-tree.zip_extjs tree

    ExtJS Tree是一个强大的JavaScript库,专门用于创建交互式的树形结构。这个"extjs-tree.zip"文件包含了使用Java编写的ExtJS异步树形控件的示例代码,旨在帮助开发者快速理解和应用这一功能。ExtJS是Sencha公司开发的...

    extJs3升级extjs4方案

    ExtJS3 升级到 ExtJS4 方案 ExtJS3 升级到 ExtJS4 需要修改大量代码,主要是因为 ExtJS4 配备了一类新的系统,不向后兼容...ExtJS3 升级到 ExtJS4 需要修改大量代码,需要我们重新学习和适应 ExtJS4 的新特性和变化。

    extjs开发tree效果

    ExtJS是一种基于...解压并研究这些文件,可以帮助我们更好地理解和学习如何在ExtJS中开发树效果。通过阅读和学习这个示例,开发者可以掌握如何创建、操作和扩展自定义的树形组件,提升在Web应用开发中的能力。

    ExtJS4中文教程2 开发笔记 chm

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

    ExtJS4官方指南翻译:DragandDrop拖放/Grid组件/Tree组件/容器与布局

    在"ExtJS4官方指南翻译:DragandDrop拖放/Grid组件/Tree组件/容器与布局"中,我们将会探讨以下几个核心概念: 1. **Drag and Drop(拖放)**: ExtJS4提供了完善的拖放支持,允许用户通过鼠标操作在界面上移动元素...

    extjs 4学习

    对于树形组件(Tree),EXTJS 4提供了丰富的操作功能。常见的操作包括: 1. 加载:通过TreeStore的proxy获取数据并加载。 2. 节点单独刷新:可以使用`treeStore.load()`或`treeStore.reload()`,注意它们的区别在于...

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

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

    Extjs4的TreeGrid例子

    ExtJS 4是一个强大的JavaScript库,专用于构建富客户端应用程序,尤其在数据网格和树形视图方面表现出色。TreeGrid是ExtJS提供的一种复合组件,它结合了树形视图和数据网格的功能,允许用户同时展示层次结构数据和...

    extjs4 入门基础,form、grid、tree

    在学习过程中,建议参考ExtJS的官方文档,了解每个组件的详细配置和用法,同时通过编写实际项目来加深理解。此外,不断实践和探索ExtJS的高级特性,如数据绑定、插件扩展、自定义组件等,将有助于提升你的前端开发...

    extjs two tree 动态双树代码 效果图

    标题中的“extjs two tree 动态双树代码 效果图”指的是使用ExtJS框架实现的一个动态双树结构的应用。ExtJS是一个流行的JavaScript库,主要用于构建富客户端Web应用程序,它提供了丰富的组件库,其中包括树形组件。...

    ExtJS Tree教程及例子代码

    通过学习以上知识点并结合提供的源码示例,你将能够有效地在你的项目中使用和定制ExtJS Tree组件,创建出功能强大的树形视图。记得实践是检验理解的最佳方式,尝试修改示例代码,看看会有什么效果,这样能加深对这些...

    Extjs复习笔记(二十)-- tree和grid结合

    4. 自定义UX组件:可能需要自定义EXTJS的扩展(Extension或UX组件),以便在Tree节点和Grid之间建立关联,并处理数据的传递和渲染。 5. 数据同步:确保当在Grid中进行操作(如编辑、添加、删除)时,这些变化能同步...

    extjs4官方示例以及api文档html版

    这些示例涵盖了EXTJS4的各种组件和功能,包括表格(Grid)、面板(Panel)、表单(Form)、菜单(Menu)、工具栏(Toolbar)、树形视图(Tree)、图表(Charts)等。通过运行示例,你可以直观地看到组件的外观和交互...

    Extjs4使用要点个人整理

    ExtJS 是一个强大的...学习和掌握这些知识点,将有助于你深入理解和熟练运用ExtJS 4进行Web应用开发。在实际项目中,还需要理解MVC架构、布局管理、事件处理、数据绑定等核心概念,以构建出高效、响应式的用户界面。

    ExtJS4 doc文档

    这个文档集合包含了关于ExtJS4的详尽资料,是开发者学习和深入理解该框架的重要资源。文档覆盖了多个关键组件和概念,包括"data"(数据管理)、"proxy"(数据代理)、"grid"(表格视图)、"tree"(树形视图)以及...

    extjs4 项目例子

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

    extjs 写的动态加载、增删改查、拖拽Tree(完整版)

    总之,ExtJS 动态加载、增删改查和拖拽Tree的实现,结合MySQL数据库的操作,能够帮助你构建出功能强大且高效的前端数据管理界面。掌握这些技术,不仅可以提升开发效率,还能为用户提供流畅的操作体验。

    Extjs tree and Grid(Buffer Grid,Progress Grid)

    在"Extjs tree and Grid(Buffer Grid,Progress Grid)"这个主题中,我们将深入探讨这两个核心组件以及它们的特定变体——缓冲网格(Buffer Grid)和进度网格(Progress Grid)。 1. **ExtJS Tree** - 树形控件...

Global site tag (gtag.js) - Google Analytics