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字典探测用户名工具
Oct 05 Javascript
在JavaScript里嵌入大量字符串常量的实现方法
Jul 07 Javascript
Jquery实现由下向上展开效果的例子
Dec 08 Javascript
jQuery四种选择器使用及示例
Jun 05 Javascript
Vue.js学习笔记之 helloworld
Aug 14 Javascript
浅谈Node.js:Buffer模块
Dec 05 Javascript
underscore之function_动力节点Java学院整理
Jul 11 Javascript
vue中的ref和$refs的使用
Nov 22 Javascript
elementUI 动态生成几行几列的方法示例
Jul 11 Javascript
详解Nuxt.js 实战集锦
Nov 19 Javascript
Vue 组件的挂载与父子组件的传值实例
Sep 02 Javascript
Nest.js参数校验和自定义返回数据格式详解
Mar 29 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
比较strtr, str_replace和preg_replace三个函数的效率
2013/06/26 PHP
PHP的MVC模式实现原理分析(一相简单的MVC框架范例)
2014/04/29 PHP
php截取中文字符串函数实例
2015/02/23 PHP
THINKPHP支持YAML配置文件的设置方法
2015/03/17 PHP
php查询内存信息操作示例
2019/05/09 PHP
jQuery 幻灯片插件(带缩略图功能)
2011/01/24 Javascript
js动态添加onload、onresize、onscroll事件(另类方法)
2012/12/26 Javascript
JS中不为人知的五种声明Number的方式简要概述
2013/02/22 Javascript
jQuery点击tr实现checkbox选中的方法
2013/03/19 Javascript
js输出阴历、阳历、年份、月份、周示例代码
2014/01/29 Javascript
从数据库读取数据后将其输出成html标签的三种方法
2014/10/13 Javascript
老生常谈JavaScript 函数表达式
2016/09/01 Javascript
使用Bootstrap + Vue.js实现添加删除数据示例
2017/02/27 Javascript
js 中rewrap-ajax.js插件实例代码
2017/10/20 Javascript
vue.js $refs和$emit 父子组件交互的方法
2017/12/20 Javascript
vue-quill-editor+plupload富文本编辑器实例详解
2018/10/19 Javascript
在Python中操作字典之clear()方法的使用
2015/05/21 Python
Python 装饰器实现DRY(不重复代码)原则
2018/03/05 Python
Tensorflow 查看变量的值方法
2018/06/14 Python
python监控文件并且发送告警邮件
2018/06/21 Python
python3调用百度翻译API实现实时翻译
2018/08/16 Python
python中文编码与json中文输出问题详解
2018/08/24 Python
Python线程下使用锁的技巧分享
2018/09/13 Python
手把手教你使用Python创建微信机器人
2019/04/29 Python
Python导入模块包原理及相关注意事项
2020/03/25 Python
Python趣味实例,实现一个简单的抽奖刮刮卡
2020/07/18 Python
全球速卖通法国在线交易平台:AliExpress法国
2017/07/07 全球购物
意大利在线眼镜精品店:Ottica Lipari
2019/11/11 全球购物
集团公司党的群众路线教育实践活动工作总结
2014/03/03 职场文书
校园联欢晚会主持词
2014/03/17 职场文书
安全在我心中演讲稿
2014/09/01 职场文书
党的群众路线教育实践活动整改落实情况自查报告
2014/10/28 职场文书
2014年学生会工作总结范文
2014/11/07 职场文书
2014年圣诞节寄语
2014/12/08 职场文书
2015年社区环境卫生工作总结
2015/04/21 职场文书
安全教育观后感
2015/06/17 职场文书