假设您是第一次使用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. es服务

    #!/bin/bash #chkconfig:2345 20 90 #description: elastic service #processname: elastic ROOT_PATH=/es5 ...

  2. Linux环境搭建:2. 安装Ubuntu虚拟机

    我家淘宝店,主要协助同学做毕业设计:https://shop104550034.taobao.com/?spm=2013.1.1000126.d21.pPCzDZ 1. 创建虚拟机 1. 打开VMwa ...

  3. 多媒体封装格式详解---MP4

    MP4文件格式详解——结构概述 http://blog.csdn.net/pirateleo/article/details/7061452 一.基本概念 1. 文件,由许多Box和FullBox组成 ...

  4. SQL-ORDER BY 多字段排序(升序、降序)

    ORDER BY _column1, _column2; /* _column1升序,_column2升序 */   ORDER BY _column1, _column2 DESC; /* _col ...

  5. Struct2-使用随笔

    提要:最近写了一个2-3各页面的使用Struts2的Demo,在这里做下总结,都已经3年多没做J2EE了,有些感觉都快找不到了. 目录 1.必备开发工具 2.必备jar包 3.了解知识点 4.遇到的问 ...

  6. Visual studio之C#的一些常见问题

    背景 要写一个APP,APP通过串口控制下位机,在此记录C#的一些常用控件的使用办法. 正文 单击button控件,执行对应操作. 选择要操作的button控件,在属性栏内点击类似闪电标志一样的事件, ...

  7. 使用swagger实现在线api文档自动生成 在线测试api接口

    使用vs nuget包管理工具搜索Swashbuckle 然后安装便可 注释依赖于vs生成的xml注释文件

  8. python selenium --一些常用方法

    · text  获取该元素的文本 · submit  提交表单 · get_attribute  获得属性值 text   用于获取元素的文本信息 下面把百度首页底部的声明打印输出 #coding=u ...

  9. linux文本分析利器awk

    转 快速理解linux文本分析利器awk 原文链接 杜亦舒 性能与架构 awk是什么 如果工作中需要操作linux比较多,那么awk是非常值得学习的 awk是一个极其强大的文本分析工具,把文件逐行的读 ...

  10. Laravel 5 教程 - 文件上传

    一.简介 Laravel 有很棒的文件系统抽象层,是基于 Frank de Jonge 的 Flysystem 扩展包. Laravel 集成的 Flysystem 提供了简单的接口,可以操作本地端空 ...