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 相关文章推荐
javascript中String类的subString()方法和slice()方法
May 24 Javascript
JavaScript中将一个值转换为字符串的方法分析[译]
Sep 21 Javascript
script标签属性用type还是language
Jan 21 Javascript
jQuery实现select模糊查询(反射机制)
Jan 14 Javascript
js实现悬浮窗效果(支持拖动)
Mar 09 Javascript
Web制作验证码功能实例代码
Jun 19 Javascript
JS实现的ajax和同源策略(实例讲解)
Dec 01 Javascript
微信小程序实现城市列表选择
Jun 05 Javascript
vuex页面刷新后数据丢失的方法
Jan 17 Javascript
element-ui 中使用upload多文件上传只请求一次接口
Jul 19 Javascript
JS实现前端路由功能示例【原生路由】
May 29 Javascript
微信小程序以7天为周期连续签到7天功能效果的示例代码
Aug 20 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
在Windows系统上安装PHP运行环境文字教程
2010/07/19 PHP
PHP连接SQLServer2005的方法
2015/01/27 PHP
PHP使用PDO连接ACCESS数据库
2015/03/05 PHP
定位地理位置PHP判断员工打卡签到经纬度是否在打卡之内
2019/05/23 PHP
javascript实现unicode和字符的互相转换
2007/07/18 Javascript
JavaScript中关于indexOf的使用方法与问题小结
2010/08/05 Javascript
原生Javascript封装的一个AJAX函数分享
2014/10/11 Javascript
JavaScript实现向OL列表内动态添加LI元素的方法
2015/03/21 Javascript
基于JavaScript代码实现pc与手机之间的跳转
2015/12/23 Javascript
JavaScript数据绑定实现一个简单的 MVVM 库
2016/04/08 Javascript
浅谈jQuery中事情的动态绑定
2017/02/12 Javascript
webpack下实现动态引入文件方法
2018/02/22 Javascript
JavaScript中发出HTTP请求最常用的方法
2018/07/12 Javascript
Vue项目中使用jquery的简单方法
2019/05/16 jQuery
file-loader打包图片文件时路径错误输出为[object-module]的解决方法
2020/01/03 Javascript
js实现炫酷光感效果
2020/09/05 Javascript
Python Socket编程入门教程
2014/07/11 Python
python每隔N秒运行指定函数的方法
2015/03/16 Python
python使用BeautifulSoup分析网页信息的方法
2015/04/04 Python
简单介绍Python中的decode()方法的使用
2015/05/18 Python
用python写一个windows下的定时关机脚本(推荐)
2017/03/21 Python
对numpy中array和asarray的区别详解
2018/04/17 Python
PyQt5实现下载进度条效果
2018/04/19 Python
对python_discover方法遍历所有执行的用例详解
2019/02/13 Python
python实现两张图片的像素融合
2019/02/23 Python
Python异步操作MySQL示例【使用aiomysql】
2019/05/16 Python
Python安装whl文件过程图解
2020/02/18 Python
python 使用paramiko模块进行封装,远程操作linux主机的示例代码
2020/12/03 Python
css3 实现元素弧线运动的示例代码
2020/04/24 HTML / CSS
工程师自我评价怎么写
2013/09/19 职场文书
中式餐厅创业计划书范文
2014/01/23 职场文书
2014年大学班长工作总结
2014/11/14 职场文书
小区保洁员岗位职责
2015/04/10 职场文书
终止劳动合同通知书
2015/04/16 职场文书
文艺委员竞选稿
2015/11/19 职场文书
JavaScript嵌入百度地图API的最详细方法
2021/04/16 Javascript