Extjs4 Treegrid 使用心得分享(经验篇)


Posted in Javascript onJuly 01, 2013

最近调试EXTJS 4的treegrid实例,看了很多水友的文章,以及官方的demo, 没一个可靠的,全都无法显示出来。像对于我们习惯用C++的coder来说,EXTJS简直就是一群无政府土匪来维护的,官网上连个搜索框都没有,找资料基本靠遍历,还是人工的。

使用treegrid,需要在调用页面的head中加载以下几个文件:

<link rel="stylesheet" type="text/css" href="css/ext-all.css"> 
<script type="text/javascript" src="ext-all.js"></script> 
<script type="text/javascript" src="treegrid.js"></script>

然后在页面的body中写上一个div
 <div id="tree-example"></div>

以上官方就这么写的,BUT,蛋疼的是,JS里没有改,不改就没法运行成功。把treegrid.js中的renderto,改成我们的div的ID就行了。

记得把json数据文件和css文件等拷贝到调用目录下。
完成的treegrid.js代码为:

/* 
This file is part of Ext JS 4 
Copyright (c) 2011 Sencha Inc 
Contact: http://www.sencha.com/contact 
GNU General Public License Usage 
This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. 
If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact. 
*/ 
Ext.require([ 
'Ext.data.*', 
'Ext.grid.*', 
'Ext.tree.*' 
]); 
Ext.onReady(function() { 
//we want to setup a model and store instead of using dataUrl 
Ext.define('Task', { 
extend: 'Ext.data.Model', 
fields: [ 
{name: 'task', type: 'string'}, 
{name: 'user', type: 'string'}, 
{name: 'duration', type: 'string'} 
] 
}); 
var store = Ext.create('Ext.data.TreeStore', { 
model: 'Task', 
proxy: { 
type: 'ajax', 
//the store will get the content from the .json file 
url: 'treegrid.json' 
}, 
folderSort: true 
}); 
//Ext.ux.tree.TreeGrid is no longer a Ux. You can simply use a tree.TreePanel 
var tree = Ext.create('Ext.tree.Panel', { 
title: 'Core Team Projects', 
width: 500, 
height: 300, 
renderTo: 'tree-example',//2B的官方和SV党们,这里竟然是getbody,bo你妹啊。 
collapsible: true, 
useArrows: true, 
rootVisible: false, 
store: store, 
multiSelect: true, 
singleExpand: true, 
//the 'columns' property is now 'headers' 
columns: [{ 
xtype: 'treecolumn', //this is so we know which column will show the tree 
text: 'Task', 
flex: 2, 
sortable: true, 
dataIndex: 'task' 
},{ 
//we must use the templateheader component so we can use a custom tpl 
xtype: 'templatecolumn', 
text: 'Duration', 
flex: 1, 
sortable: true, 
dataIndex: 'duration', 
align: 'center', 
//add in the custom tpl for the rows 
tpl: Ext.create('Ext.XTemplate', '{duration:this.formatHours}', { 
formatHours: function(v) { 
if (v < 1) { 
return Math.round(v * 60) + ' mins'; 
} else if (Math.floor(v) !== v) { 
var min = v - Math.floor(v); 
return Math.floor(v) + 'h ' + Math.round(min * 60) + 'm'; 
} else { 
return v + ' hour' + (v === 1 ? '' : 's'); 
} 
} 
}) 
},{ 
text: 'Assigned To', 
flex: 1, 
dataIndex: 'user', 
sortable: true 
}] 
}); 
});
Javascript 相关文章推荐
教你如何解密js/vbs/vbscript加密的编码异处理小结
Jun 25 Javascript
javascript 系统文件夹文件操作及参数介绍
Jan 08 Javascript
js实现表格字段排序
Feb 19 Javascript
js实现点击链接后窗口缩小并居中的方法
Mar 02 Javascript
微信中一些常用的js方法汇总
Mar 12 Javascript
jqGrid表格应用之新增与删除数据附源码下载
Dec 02 Javascript
js调出上下文菜单的实例
Dec 17 Javascript
基于JavaScript实现动态创建表格和增加表格行数
Dec 20 Javascript
浅析Vue.js 中的条件渲染指令
Nov 19 Javascript
简单的React SSR服务器渲染实现
Dec 11 Javascript
使用vue自定义指令开发表单验证插件validate.js
May 23 Javascript
Vue实现简单计算器案例
Feb 25 Javascript
原生javascript兼容性测试实例
Jul 01 #Javascript
面向对象继承实例(a如何继承b问题)(自写)
Jul 01 #Javascript
批量实现面向对象的实例代码
Jul 01 #Javascript
js原生appendChild的bug解决心得分享
Jul 01 #Javascript
Jquery时间验证和转换工具小例子
Jul 01 #Javascript
JS 两日期相减,获得天数的小例子(兼容IE,FF)
Jul 01 #Javascript
js函数排序的实例代码
Jul 01 #Javascript
You might like
基于php socket(fsockopen)的应用实例分析
2013/06/02 PHP
php的hash算法介绍
2014/02/13 PHP
ThinkPHP行为扩展Behavior应用实例详解
2014/07/22 PHP
PHP的Yii框架的基本使用示例
2015/08/21 PHP
PHP 下载文件时如何自动添加bom头及解释BOM头和去掉bom头的方法
2016/01/04 PHP
Symfony查询方法实例小结
2017/06/28 PHP
php对象工厂类完整示例
2018/08/09 PHP
js 颜色选择器(兼容firefox)
2009/03/05 Javascript
EasyUi tabs的高度与宽度根据IE窗口的变化自适应代码
2010/10/26 Javascript
多个$(document).ready()的执行顺序实例分析
2014/07/26 Javascript
jquery制作 随机弹跳的小球特效
2015/02/01 Javascript
基于jQuery实现最基本的淡入淡出效果实例
2015/02/02 Javascript
jQuery插件Elastislide实现响应式的焦点图无缝滚动切换特效
2015/04/12 Javascript
js字符串操作总结(必看篇)
2016/11/22 Javascript
SVG描边动画
2017/02/23 Javascript
js获取文件里面的所有文件名(实例)
2017/10/17 Javascript
vue动态绑定class的几种常用方式小结
2019/05/21 Javascript
Vue 实现可视化拖拽页面编辑器
2021/02/01 Vue.js
python实现的重启关机程序实例
2014/08/21 Python
Python接收Gmail新邮件并发送到gtalk的方法
2015/03/10 Python
Python 常用string函数详解
2016/05/30 Python
Python3.6笔记之将程序运行结果输出到文件的方法
2018/04/22 Python
Python 一行代码能实现丧心病狂的功能
2020/01/18 Python
Python networkx包的实现
2020/02/14 Python
Python实现对adb命令封装
2020/03/06 Python
Python+Xlwings 删除Excel的行和列
2020/12/19 Python
美国著名童装品牌:OshKosh B’gosh
2016/08/05 全球购物
澳大利亚购买最佳炊具品牌网站:Cookware Brands
2019/02/16 全球购物
程序集与命名空间有什么不同
2014/07/25 面试题
上班离岗检讨书
2014/01/27 职场文书
教师节促销活动方案
2014/02/14 职场文书
医院竞聘演讲稿
2014/05/16 职场文书
机关作风整顿个人整改措施思想汇报
2014/09/29 职场文书
领导干部整治奢华浪费之风思想汇报
2014/10/07 职场文书
导游词之淮安明祖陵
2019/11/25 职场文书
Spring JPA 增加字段执行异常问题及解决
2022/06/10 Java/Android