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 相关文章推荐
关于IE BUG与字符串截取substr的解决办法
Apr 10 Javascript
jQuery获取CSS样式中的颜色值的问题,不同浏览器格式不同的解决办法
May 13 Javascript
Jquery时间验证和转换工具小例子
Jul 01 Javascript
Jquery实现搜索框提示功能示例代码
Aug 13 Javascript
使用JavaScript脚本判断页面是否在微信中被打开
Mar 06 Javascript
Jquery技巧(必须掌握)
Mar 16 Javascript
vue2滚动条加载更多数据实现代码
Jan 10 Javascript
简单实现jquery隔行变色
Nov 09 jQuery
JS实现HTML页面中动态显示当前时间完整示例
Jul 30 Javascript
Angular服务Request异步请求的实例讲解
Aug 13 Javascript
这应该是最详细的响应式系统讲解了
Jul 22 Javascript
JavaScript实现页面高亮操作提示和蒙板
Jan 04 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 将bmp图片转为jpg等其他任意格式的图片
2009/06/29 PHP
php中通过数组进行高效随机抽取指定条记录的算法
2013/09/09 PHP
PHP实现的购物车类实例
2015/06/17 PHP
php获取指定(访客)IP所有信息(地址、邮政编码、国家、经纬度等)的方法
2015/07/06 PHP
Zend Framework分页类用法详解
2016/03/22 PHP
php7连接MySQL实现简易查询程序的方法
2020/10/13 PHP
拥抱模块化的JavaScript
2012/03/07 Javascript
浅析JavaScript中的typeof运算符
2013/11/30 Javascript
jquery搜索框效果实现方法
2015/01/16 Javascript
深入理解JavaScript编程中的原型概念
2015/06/25 Javascript
第二章之Bootstrap 页面排版样式
2016/04/25 Javascript
使用jquery/js获取iframe父子级、同级获取元素的方法
2016/08/05 Javascript
原生js封装运动框架的示例讲解
2017/10/01 Javascript
jQuery基于cookie实现换肤功能实例
2017/10/14 jQuery
理解Koa2中的async&amp;await的用法
2018/02/05 Javascript
vue组件详解之使用slot分发内容
2018/04/09 Javascript
基于React+Redux的SSR实现方法
2018/07/03 Javascript
vue.js实现的经典计算器/科学计算器功能示例
2018/07/11 Javascript
JS实现方形抽奖效果
2018/08/27 Javascript
从零开始实现Vue简单的Toast插件
2018/12/03 Javascript
通过javascript实现扫雷游戏代码实例
2020/02/09 Javascript
JS实现联想、自动补齐国家或地区名称的功能
2020/07/07 Javascript
[00:35]TI7不朽珍藏III——寒冰飞龙不朽展示
2017/07/15 DOTA
Pyramid添加Middleware的方法实例
2013/11/27 Python
python executemany的使用及注意事项
2017/03/13 Python
python实现点击按钮修改数据的方法
2019/07/17 Python
Python从文件中读取指定的行以及在文件指定位置写入
2019/09/06 Python
Python+numpy实现矩阵的行列扩展方式
2019/11/29 Python
Keras 使用 Lambda层详解
2020/06/10 Python
中国电子产品批发商/跨境电商/外贸网:Sunsky-online
2020/04/20 全球购物
手机促销活动方案
2014/02/05 职场文书
创业大赛策划书
2014/03/01 职场文书
教师节主持词开场白
2015/05/29 职场文书
MySQL Server 层四个日志
2022/03/31 MySQL
Python写情书? 10行代码展示如何把情书写在她的照片里
2022/04/21 Python
Java 中的 Lambda List 转 Map 的多种方法详解
2022/07/07 Java/Android