请求帮助,Extjs treegrid 数据显示问题

zhiwu891123 2010-04-17 10:21:34
大家好,我是新手,最近遇到一个Extjs的问题,由于项目需要用到Extjs 但是我从来没接触过,现在要做一个页面, 用columntree 或者 treegrid 但是无法动态生成数据,请各位大侠帮帮忙,告诉我怎么实现,小弟在此 万分感谢!
Ext.onReady(function() {
Ext.QuickTips.init();

var toolbar = new Ext.Toolbar({
height: 30,
hideBorders: true,
buttons: [{
text: ' 新建机构',
icon: 'img/icon042a2.gif'


}, {
text: ' 编辑',
icon: 'img/icon042a4.gif'
}, {
text: ' 删除',
icon: 'img/icon042a3.gif'
}]
});



var sm = new Ext.grid.CheckboxSelectionModel();



var tree = new Ext.ux.tree.TreeGrid({

width: 900,
height: 300,
renderTo: Ext.getBody(),
enableDD: true,
tbar: toolbar,
columns: [

{
header: 'Task',
dataIndex: 'task',
width: 300
}, {
header: 'Duration',
width: 300,
dataIndex: 'duration',
align: 'center',
sortType: 'asFloat',
tpl: new 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');
}
}
})
}, {
header: 'Assigned To',
width: 300,
dataIndex: 'user'
}],
dataUrl: 'treegrid-data.json'
});


treegrid-data.json文件:
[{
task:'Project: Shopping',
duration:13.25,
user:'Tommy Maintz',
iconCls:'task-folder',
expanded: true,
children:[{
task:'Housewares',
duration:1.25,
user:'Tommy Maintz',
iconCls:'task-folder',
children:[{
task:'Kitchen supplies',
duration:0.25,
user:'Tommy Maintz',
leaf:true,
iconCls:'task'
},{
task:'Groceries',
duration:.4,
user:'Tommy Maintz',
leaf:true,
iconCls:'task'
},{
task:'Cleaning supplies',
duration:.4,
user:'Tommy Maintz',
leaf:true,
iconCls:'task'
},{
task: 'Office supplies',
duration: .2,
user: 'Tommy Maintz',
leaf: true,
iconCls: 'task'
}]
}, {
task:'Remodeling',
duration:12,
user:'Tommy Maintz',
iconCls:'task-folder',
expanded: true,
children:[{
task:'Retile kitchen',
duration:6.5,
user:'Tommy Maintz',
leaf:true,
iconCls:'task'
},{
task:'Paint bedroom',
duration: 2.75,
user:'Tommy Maintz',
iconCls:'task-folder',
children: [{
task: 'Ceiling',
duration: 1.25,
user: 'Tommy Maintz',
iconCls: 'task',
leaf: true
}, {
task: 'Walls',
duration: 1.5,
user: 'Tommy Maintz',
iconCls: 'task',
leaf: true
}]
},{
task:'Decorate living room',
duration:2.75,
user:'Tommy Maintz',
leaf:true,
iconCls:'task'
},{
task: 'Fix lights',
duration: .75,
user: 'Tommy Maintz',
leaf: true,
iconCls: 'task'
}, {
task: 'Reattach screen door',
duration: 2,
user: 'Tommy Maintz',
leaf: true,
iconCls: 'task'
}]
}]
},{
task:'Project: Testing',
duration:2,
user:'Core Team',
iconCls:'task-folder',
children:[{
task: 'Mac OSX',
duration: 0.75,
user: 'Tommy Maintz',
iconCls: 'task-folder',
children: [{
task: 'FireFox',
duration: 0.25,
user: 'Tommy Maintz',
iconCls: 'task',
leaf: true
}, {
task: 'Safari',
duration: 0.25,
user: 'Tommy Maintz',
iconCls: 'task',
leaf: true
}, {
task: 'Chrome',
duration: 0.25,
user: 'Tommy Maintz',
iconCls: 'task',
leaf: true
}]
},{
task: 'Windows',
duration: 3.75,
user: 'Darrell Meyer',
iconCls: 'task-folder',
children: [{
task: 'FireFox',
duration: 0.25,
user: 'Darrell Meyer',
iconCls: 'task',
leaf: true
}, {
task: 'Safari',
duration: 0.25,
user: 'Darrell Meyer',
iconCls: 'task',
leaf: true
}, {
task: 'Chrome',
duration: 0.25,
user: 'Darrell Meyer',
iconCls: 'task',
leaf: true
},{
task: 'Internet Exploder',
duration: 3,
user: 'Darrell Meyer',
iconCls: 'task',
leaf: true
}]
},{
task: 'Linux',
duration: 0.5,
user: 'Aaron Conran',
iconCls: 'task',
children: [{
task: 'FireFox',
duration: 0.25,
user: 'Aaron Conran',
iconCls: 'task',
leaf: true
}, {
task: 'Chrome',
duration: 0.25,
user: 'Aaron Conran',
iconCls: 'task',
leaf: true
}]
}]
}]
...全文
1151 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
班门弄斧 2011-04-15
  • 打赏
  • 举报
回复
var sm = new Ext.grid.CheckboxSelectionModel();
楼主你这个代码在下面怎么没有引用
图_钉 2011-01-02
  • 打赏
  • 举报
回复
先建个虚拟目录比如:http://localhost:82/
然后把extjs框架目录复制进去,
类似如下访问官方示例:http://localhost:82/ext-3.2.1/examples/treegrid/treegrid.html
具体路径与你下载的extjs版本和目录有关系。
mmxhere 2010-12-30
  • 打赏
  • 举报
回复
我也碰到这样的问题,部署到tomcat里就能看到数据了
licip 2010-10-07
  • 打赏
  • 举报
回复
用fireBug调试一下吧。看执行到后台了吗?
erysfeipeng1989 2010-10-07
  • 打赏
  • 举报
回复
学习中。。。。。。。
zhengqingming 2010-06-23
  • 打赏
  • 举报
回复
谢谢 楼主
hoojo 2010-06-22
  • 打赏
  • 举报
回复
数据没加载成功吧
hyc023 2010-06-22
  • 打赏
  • 举报
回复
我也试验了这个范例,也是不显示,搞不懂什么问题?而且extjs官网上显示的是2.0的样式,晕

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧