求助!Ext4.0中treegrid如何获得和处理Servlet传来的Json数据

macy212 2012-02-23 10:04:51
问题是这样的。最近在做一个查询系统,记录中有父记录和子记录,于是找到了ext的treegrid插件,也是第一次使用。只是改了一下官网下载的案例,只改动了一些列。
打算将treegrid嵌入到<form></form>中,当进入到这个页面时,treegrid是空的,当用户查询时(通过ajax异步提交数据,该页面不跳转),后台将查询结果组织成Json字符串传递到前台,treegrid解析json显示。
现在遇到的主要问题是对treegrid加载数据的方式不理解,proxy的type是ajax,当一进入这个页面时就会加载treegrid.json,这是官方的实现。而小弟要实现的是第一次进入这个页面时不加载,只有当ajax成功返回以后treegrid才加载数据。现在后台数据已经组织好,将打印出的数据拷贝到现有的treegrid.json中能实现属性所示,如下图。现在对前台如何处理返回的json数据一知半解,望各位大虾指教。感激不尽!
如图所示


这是改了官网例子以后的treegrid.js

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('strSiteName', {
extend: 'Ext.data.Model',
fields: [

{name: 'strSiteName', type: 'string'},
{name: 'flaSiteScore', type: 'double'},
{name: 'flaInfoDisclosureScore', type: 'double'},
{name: 'flaOnlineServicesScore', type: 'double'},
{name: 'flaPublicParticipationSore', type: 'double'},
{name: 'flaWebDesignScore', type: 'double'},
{name: 'flaDailyScore', type: 'double'}

]
});

var store = Ext.create('Ext.data.TreeStore', {
model: 'strSiteName',
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: 'Duration',
width: 800,
height: 300,
renderTo: Ext.getBody(),
collapsible: true,
useArrows: true,
rootVisible: false,
store: store,
multiSelect: true,
singleExpand: false,
//the 'columns' property is now 'headers'
columns: [{
xtype: 'treecolumn', //this is so we know which column will show the tree
text: '网站名称',
flex: 8,

sortable: true,
dataIndex: 'strSiteName'
},{

text: '总分',
flex: 5,
sortable: true,
dataIndex: 'flaSiteScore'
},{

text: '公开',
flex: 5,
sortable: true,
dataIndex: 'flaInfoDisclosureScore'
},{

text: '在线办事',
flex: 5,
sortable: true,
dataIndex: 'flaOnlineServicesScore'
},{

text: '公众参与',
flex: 5,
sortable: true,
dataIndex: 'flaPublicParticipationSore'
},{

text: '网站性能及设计',
flex: 5,
sortable: true,
dataIndex: 'flaWebDesignScore'
},{

text: '日常保障',
flex: 5,
sortable: true,
dataIndex: 'flaDailyScore'
} ]
});
});

...全文
457 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
macy212 2012-03-04
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 java_amateur 的回复:]

请问 “官网”的例子在哪里下载的?能否给个链接 供学习下?
谢谢~
[/Quote]
http://www.sencha.com/products/extjs/download?page=a
官网可以下,下open source version里面有例子
齊麟 2012-02-28
  • 打赏
  • 举报
回复
tree中 试下:loadStore:false

或者

store中 试下:autoLoad:false
齊麟 2012-02-28
  • 打赏
  • 举报
回复
请问 “官网”的例子在哪里下载的?能否给个链接 供学习下?
谢谢~

87,989

社区成员

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

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