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 相关文章推荐
JQuery for与each性能比较分析
May 14 Javascript
js中substring和substr的详细介绍与用法
Aug 29 Javascript
JS实现一个列表中包含上移下移删除等功能
Sep 24 Javascript
用模版生成HTML的的框架jquery.tmpl使用详解
Jan 07 Javascript
jQuery实现按键盘方向键翻页特效
Mar 18 Javascript
js倒计时显示实例
Dec 11 Javascript
防止重复发送 Ajax 请求
Feb 15 Javascript
React Native中TabBarIOS的简单使用方法示例
Oct 13 Javascript
JavaScript生成指定范围随机数和随机序列的方法
May 05 Javascript
详解Vue-axios 设置请求头问题
Dec 06 Javascript
浅析JavaScript 函数柯里化
Sep 08 Javascript
用Javascript实现发送短信验证码间隔功能
Feb 08 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
一条久听不愿放下的DIY森海MX500,三言两语话神奇
2021/03/02 无线电
PHP取得一个类的属性和方法的实现代码
2011/05/22 PHP
PHP的SQL注入过程分析
2012/01/06 PHP
PHP+AJAX 投票器功能
2017/11/11 PHP
php数组和链表的区别总结
2019/09/20 PHP
基于jquery实现的上传图片及图片大小验证、图片预览效果代码
2011/04/12 Javascript
js控制的遮罩层实例介绍
2013/05/29 Javascript
jQuery实现企业网站横幅焦点图切换功能实例
2015/04/30 Javascript
JavaScript中数据结构与算法(一):栈
2015/06/19 Javascript
ECMAScript6快速入手攻略
2016/07/18 Javascript
jQuery中ztree 点击文本框弹出下拉框的实例代码
2017/02/05 Javascript
JS解决IOS中拍照图片预览旋转90度BUG的问题
2017/09/13 Javascript
浅谈JavaScript中的属性:如何遍历属性
2017/09/14 Javascript
vue 计时器组件的实现代码
2017/09/14 Javascript
ui-router中使用ocLazyLoad和resolve的具体方法
2017/10/18 Javascript
详解Vue源码中一些util函数
2019/04/24 Javascript
微信小程序云开发之使用云数据库
2019/05/17 Javascript
微信小程序学习总结(四)事件与冒泡实例分析
2020/06/04 Javascript
基于JavaScript实现猜数字游戏代码实例
2020/07/30 Javascript
[44:09]DOTA2上海特级锦标赛A组小组赛#1 EHOME VS MVP.Phx第二局
2016/02/25 DOTA
采用Psyco实现python执行速度提高到与编译语言一样的水平
2014/10/11 Python
Python列表(list)、字典(dict)、字符串(string)基本操作小结
2014/11/28 Python
python生成器generator用法实例分析
2015/06/04 Python
Python实现小数转化为百分数的格式化输出方法示例
2017/09/20 Python
win10 64bit下python NLTK安装教程
2018/09/19 Python
使用Python在Windows下获取USB PID&amp;VID的方法
2019/07/02 Python
对django 模型 unique together的示例讲解
2019/08/06 Python
python编写微信公众号首图思路详解
2019/12/13 Python
python opencv实现信用卡的数字识别
2020/01/12 Python
Python析构函数__del__定义原理解析
2020/11/20 Python
社会实践感言
2014/01/25 职场文书
心理健康课教学反思
2014/02/13 职场文书
导游个人求职信范文
2014/03/23 职场文书
教师节活动总结
2014/08/29 职场文书
Python网络编程之ZeroMQ知识总结
2021/04/25 Python
Python使用DFA算法过滤内容敏感词
2022/04/22 Python