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显示和隐藏元素或设为只读(含Ligerui的控件禁用,实例说明介绍)
Jul 09 Javascript
jquery等宽输出文字插件使用介绍
Sep 18 Javascript
jQuery调用RESTful WCF示例代码(GET方法/POST方法)
Jan 26 Javascript
JavaScript中的style.cssText使用教程
Nov 06 Javascript
VS2008中使用JavaScript调用WebServices
Dec 18 Javascript
jQuery Easy UI中根据第一个下拉框选中的值设置第二个下拉框是否可以编辑
Nov 29 Javascript
实例解析Array和String方法
Dec 14 Javascript
如何开发出更好的JavaScript模块
Dec 22 Javascript
Angular使用cli生成自定义文件、组件的方法
Sep 04 Javascript
vue项目出现页面空白的解决方案
Oct 31 Javascript
JavaScript实现英语单词题库
Dec 24 Javascript
swiper4实现移动端导航栏tab滑动切换
Oct 16 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
中东人咖啡哲学
2021/03/03 咖啡文化
php+jquery编码方面的一些心得(utf-8 gb2312)
2010/10/12 PHP
php设计模式 DAO(数据访问对象模式)
2011/06/26 PHP
跟我学Laravel之请求与输入
2014/10/15 PHP
中高级PHP程序员应该掌握哪些技术?
2016/09/23 PHP
完美兼容各大浏览器的jQuery仿新浪图文淡入淡出间歇滚动特效
2014/11/12 Javascript
JavaScript获得表单target属性的方法
2015/04/02 Javascript
基于jQuery和CSS3制作响应式水平时间轴附源码下载
2015/12/20 Javascript
JavaScript数据结构与算法之集合(Set)
2016/01/29 Javascript
ionic 上拉菜单(ActionSheet)实例代码
2016/06/06 Javascript
JS中绑定事件顺序(事件冒泡与事件捕获区别)
2017/01/24 Javascript
jquery处理checkbox(复选框)是否被选中实例代码
2017/06/12 jQuery
详解在vue-cli项目中安装node-sass
2017/06/21 Javascript
vue判断input输入内容全是空格的方法
2018/03/02 Javascript
python实现批量转换文件编码(批转换编码示例)
2014/01/23 Python
Python中返回字典键的值的values()方法使用
2015/05/22 Python
Python实现的井字棋(Tic Tac Toe)游戏示例
2018/01/31 Python
Python爬取视频(其实是一篇福利)过程解析
2019/08/01 Python
django框架使用views.py的函数对表进行增删改查内容操作详解【models.py中表的创建、views.py中函数的使用,基于对象的跨表查询】
2019/12/12 Python
python实现自动打卡的示例代码
2020/10/10 Python
让你相见恨晚的十个Python骚操作
2020/11/18 Python
HTML5实现移动端复制功能
2018/04/19 HTML / CSS
英国在线发型和美容产品商店:Beauty Cutie
2019/04/27 全球购物
远程研修随笔感言
2014/02/10 职场文书
幼儿园家长寄语
2014/04/02 职场文书
党员领导干部民主生活会批评与自我批评发言
2014/09/28 职场文书
2014年数学教师工作总结
2014/12/03 职场文书
酒店财务总监岗位职责
2015/04/03 职场文书
从事会计工作年限证明
2015/06/23 职场文书
班主任经验交流心得体会
2015/11/02 职场文书
七年级作文之游记
2019/12/11 职场文书
HTML基础-标签分类(闭合标签,空标签,块级元素,行内元素,行级块元素,可替换元素)
2021/03/31 HTML / CSS
pytorch实现线性回归以及多元回归
2021/04/11 Python
SpringBoot整合MongoDB的实现步骤
2021/06/23 MongoDB
python的列表生成式,生成器和generator对象你了解吗
2022/03/16 Python
Android开发EditText禁止输入监听及InputFilter字符过滤
2022/06/10 Java/Android