假设您是第一次使用ExtJS的TreeGrid的话,我相信总会有一些小麻烦的,以下就来说一说ExtJS中TreeGrid的使用。

本人使用的ExtJS版本号为4.1.1,而且使用了MVC模式。假设不了解ExtJS的MVC模式的话我个认为还是有必要去学学的,

学完后你肯定会喜欢上的。

事实上在ExtJS中并没有TreeGrid这么一个类,这个说法是从EasyUI中借用过来的,ExtJS中的TreeGrid功能已经合在了Ext.tree.Panel中。

TreeGrid显示出来大概是这个样子:

以下是这个样例的源代码:

View:

Ext.define("node.view.NodeListPanel", {
extend : "Ext.tree.Panel",
alias : "widget.nodelistpanel",
title : "节点管理",
columnLines : true,
region: 'center',
root:{
id:'root',
name:'节点管理',
expanded:true
},
columns: [{
xtype : 'treecolumn',
header: '节点名称', dataIndex: 'name', sortable:false,flex:1
}, {
header: '节点编码', dataIndex: 'code',align : 'center',sortable:false,width:150
}, {
header: '节点IP', dataIndex: 'ip', align : 'center',sortable:false,width:150
}, {
header: '端口号', dataIndex: 'port',align : 'center',sortable:false,width:50
}, {
header: '节点描写叙述', dataIndex: 'desc',align : 'center',sortable:false,width:200
}],
loadMask:{
msg : '正在载入数据,请稍等...'
},
store : Ext.create('node.store.NodeStore'),
//store : "NodeStore",
renderTo: Ext.getBody()
});

Store:

Ext.define("node.store.NodeStore", {
extend : 'Ext.data.TreeStore',
//model : 'node.model.Node',//用model传递不了数据
proxy : {
type : 'ajax',
url : 'data/NodeTree.json',
reader : 'json',
autoLoad : true
},
fields : [{
name: 'id',
type: 'string'
}, {
name: 'name',
type: 'string'
}, {
name: 'code',
type: 'string'
}, {
name: 'ip',
type: 'string'
}, {
name: 'port',
type: 'string'
}, {
name: 'desc',
type: 'string'
}] });

NodeTree.json :

{
"id":"root",
"leaf":false,
"name" : "root",
"children":[{
"id":"1",
"leaf":true,
"name" : "公安",
"code" : 452363214,
"ip" : "192.168.0.203",
"port" : 8080,
"desc" : "公安节点"
}, {
"id":"4",
"leaf":true,
"name" : "法院",
"code" : 452364587,
"ip" : "192.168.0.204",
"port" : null,
"desc" : "法院节点"
}, {
"id":"9",
"leaf":true,
"name" : "检查院",
"code" : 452312365,
"ip" : "192.168.0.205",
"port" : null,
"desc" : "检查院节点"
}, {
"id":"10",
"leaf":false,
"name" : "纪检委",
"code" : 45234596,
"ip" : "192.168.0.235",
"port" : null,
"desc" : "纪检委节点",
"expanded":true,
"children":[{
"id":"2",
"leaf":true,
"name" : "測试节点",
"code" : 45239658,
"ip" : "192.168.0.255",
"port" : null,
"desc" : "測试节点"
}]
}]
}

Controller:

Ext.define('node.controller.NodeController', {
extend:'Ext.app.Controller',
init:function(){
this.control({ });
},
views: [
'NodeListPanel'
],
stores: [
//"NodeStore"
],
models: [
//"Node"
]
});

app.js :

Ext.onReady(function(){
Ext.Loader.setConfig({
enabled : true
}); Ext.application({
name : "node",
appFolder : ".",
launch : function() {
Ext.create("Ext.container.Viewport", {
layout : "border",
items : [{
xtype : "nodelistpanel"
}]
});
},
controllers : [
'NodeController'
]
});
});

在这里有两个非常奇怪的地方:

1. NodeListPanel指定Store时,不能直接配置成store:"NodeStore"让其动态载入,而要直接创建出来,所以在Controller中不指定NodeStore也是能够的

2. NodeStore不能直接指定Model。而应该配置其fields属性取代,由于配置Model对TreeStore来说根本不起作用

以上两点至于为什么会这样,本人也没有去深究,望高人直接指点。



另一个须要注意的地方就是一定要为TreePanel配置root属性,否则无法显示树形

ExtJS TreeGrid的使用方法的更多相关文章

  1. Extjs 选择元素涉及方法总结

    本文主要是解释Extjs在使用过程中使用的相关选择方法: 1.首先解释第一组概念: Ext.get(String/HTMLElement/Ext.Element el) Ext.getCmp(Stri ...

  2. [ExtJS5学习笔记]第三十五节 sencha extjs 5 组件查询方法总结

    一个UI前台组件肯定会比较多,我们通常习惯性的使用ID来获取需要操作的组件,但是这种方法是extjs推荐的么?有没有extjs推荐使用的获取组件的方法呢? 目录 目录 extjs的查询组件的API 查 ...

  3. [转]Extjs中的迭代方法

    原文地址:http://www.veryhuo.com/a/view/36701.html EXTJS 有很多的迭代方法,例如,你也许已知道的Ext.each,但还有另外一些不为人知且很有用的方法.首 ...

  4. [ExtJS5学习笔记]第三十五条 sencha extjs 5 组件查询方法

    一UI前部组件势必更加,我们通常习惯性使用ID获取部件操作的需要.但是,这种方法是extjs推荐么?你有吗extjs利用它来获取组件的推荐方法? 夹 文件夹 extjs的查询组件的API 查询实例 主 ...

  5. Extjs 一些配置以及方法

    1.例如想要实现以下功能,本来model中只有用户的firstname和lastname,但是在grid中展示还需要展示用户姓名,或者只展示用户姓名

  6. ExtJs radiogroup form.loadRecord方法无法赋值正确解决办法

    一.radiogroup的name和radio的name一致,inputValue为整形 { xtype: 'radiogroup', fieldLabel: '是否有效', name: 'statu ...

  7. Extjs 分页传参方法

    第一种(常用): var proxy = new Ext.data.HttpProxy({url : url}) var store = new Ext.data.Store({ pruneModif ...

  8. EasyUI treegrid 获取编辑状态中某字段的值 [getEditor方法获取不到editor]

    如题,在treegrid里,按照api里getEditor方法的说明, getEditoroptionsGet the specified editor, the options contains t ...

  9. ExtJS 中类的选项 - config

    首先看一个例子,我们在ExtJS中定义一个Window对象,代码如下: var win = Ext.create("Ext.window.Window", { title: '示例 ...

随机推荐

  1. 【云计算】Docker容器时间同步如何配置?

    示例: # 3.8 配置时区.时钟同步 # configure timezone & ntp RUN echo ${TIME_ZONE} > /etc/timezone \ && ...

  2. 报错:configure: error: no acceptable C compiler found in $PATH

    运行以下命令报错: ./configure 错误: checking whether to enable maintainer-specific portions of Makefiles... ye ...

  3. 转: codereview 工具平台建设

    一.  Rietveld  code review  (一套工具系统与平台) 1. http://www.cnblogs.com/fang9159/archive/2012/07/20/2591690 ...

  4. 算法笔记_078:蓝桥杯练习 最大最小公倍数(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 问题描述 已知一个正整数N,问从1~N中任选出三个数,他们的最小公倍数最大可以为多少. 输入格式 输入一个正整数N. 输出格式 输出一个整数,表示你 ...

  5. JavaScript 数组去重并统计重复元素出现的次数

    1.方法一 var arr = [1, 2, 3, 1, 2, 4]; function arrayCnt(arr) { var newArr = []; for(var i = 0; i < ...

  6. <译>Spark Sreaming 编程指南

    Spark Streaming 编程指南 Overview A Quick Example Basic Concepts Linking Initializing StreamingContext D ...

  7. Docker技术-cgroup

    分类: 虚拟化 Docker容器采用了linux内核中的cgroup技术来实现container的资源的隔离和控制. 关于cgroup我们需要了解的它的知识点: 1. 基本概念 cgroup涉及到几个 ...

  8. docker build 的 cache 机制

    cache 机制注意事项 可以说,cache 机制很大程度上做到了镜像的复用,降低存储空间的同时,还大大缩短了构建时间.然而,不得不说的是,想要用好 cache 机制,那就必须了解利用 cache 机 ...

  9. 后台dubug有值且sql也打印出来执行了但是前台就是查不到数据

    记录在sturts2里面 摔得最深的一次 public String queryJoinAccount(){ //用来存储分页的数据 pageMap=new HashMap<String, Ob ...

  10. C# 视频监控系列:学习地址汇总

    原文地址:http://www.cnblogs.com/over140/archive/2009/04/07/1429308.html 前言 对于视频监控系统大家应该是不陌生的,实施的路况信息.地铁. ...