先上效果图:
其中
系统设置、会员管理 是一级菜单
其他有二级和三级菜单;
view 代码如下:
$(function () { $('#easyui_grid').treegrid({ title: '系统权限', //width: 700, height: 450, nowrap: false, rownumbers: true, animate: true, collapsible: true, method: 'post', //url: '/Scripts/jquery-easyui-1.3.1/demo/treegrid_data.json', //从远程站点获取数据 url: '/Admin/Systems/Power_Manage_Json', idField: 'current_id', //说明哪个字段是一个标识字段 treeField: 'current_id', columns: [[ { title: '权限名称', field: 'power_name', width: 150 }, { field: 'power_src', title: '链接地址', width: 200, rowspan: 2 }, { field: 'power_deleted', title: '删除', rowspan: 2 }, { field: 'power_description', title: '描述', rowspan: 2 } ]], toolbar: [ { text: '新增', iconCls: 'icon-add', handler: InsertData } ], onLoadError: function (arguments) { alert(arguments); } }); });
view html 如下:
<table id="easyui_grid"> </table>
服务端 /Admin/Systems/Power_Manage_Json 返回Json如下:
[{
"power_id": "1",
"power_guid": "9cd32f9c-ab57-46e8-a8ac-f9cb1a7b7543",
"power_name": "系统设置",
"power_src": "",
"power_ico": "",
"power_description": "",
"power_index": "0",
"power_parentid": "0",
"power_deleted": "False",
"power_deletedtime": "",
"parent_id": "0",
"current_id": "1",
"children": [{
"power_id": "8",
"power_guid": "9cd32f9c-ab57-46e8-a8ac-f9cb1a7b7547",
"power_name": "权限设置",
"power_src": "",
"power_ico": "",
"power_description": "",
"power_index": "0",
"power_parentid": "1",
"power_deleted": "False",
"power_deletedtime": "",
"parent_id": "1",
"current_id": "8",
"children": [{
"power_id": "12",
"power_guid": "9cd32f9c-ab57-46e8-a8ac-f9cb1a7b7551",
"power_name": "权限管理",
"power_src": "",
"power_ico": "",
"power_description": "",
"power_index": "0",
"power_parentid": "8",
"power_deleted": "False",
"power_deletedtime": "",
"parent_id": "8",
"current_id": "12"
},
{
"power_id": "13",
"power_guid": "9cd32f9c-ab57-46e8-a8ac-f9cb1a7b7552",
"power_name": "角色管理",
"power_src": "",
"power_ico": "",
"power_description": "",
"power_index": "0",
"power_parentid": "8",
"power_deleted": "False",
"power_deletedtime": "",
"parent_id": "8",
"current_id": "13"
}]
},
{
"power_id": "9",
"power_guid": "9cd32f9c-ab57-46e8-a8ac-f9cb1a7b7548",
"power_name": "仓库管理",
"power_src": "",
"power_ico": "",
"power_description": "",
"power_index": "0",
"power_parentid": "1",
"power_deleted": "False",
"power_deletedtime": "",
"parent_id": "1",
"current_id": "9",
"children": [{
"power_id": "14",
"power_guid": "9cd32f9c-ab57-46e8-a8ac-f9cb1a7b7553",
"power_name": "新建仓库",
"power_src": "",
"power_ico": "",
"power_description": "",
"power_index": "0",
"power_parentid": "9",
"power_deleted": "False",
"power_deletedtime": "",
"parent_id": "9",
"current_id": "14"
},
{
"power_id": "15",
"power_guid": "9cd32f9c-ab57-46e8-a8ac-f9cb1a7b7554",
"power_name": "仓库维护",
"power_src": "",
"power_ico": "",
"power_description": "",
"power_index": "0",
"power_parentid": "9",
"power_deleted": "False",
"power_deletedtime": "",
"parent_id": "9",
"current_id": "15"
}]
}]
},
{
"power_id": "2",
"power_guid": "9cd32f9c-ab57-46e8-a8ac-f9cb1a7b7541",
"power_name": "会员管理",
"power_src": "",
"power_ico": "",
"power_description": "",
"power_index": "0",
"power_parentid": "0",
"power_deleted": "False",
"power_deletedtime": "",
"parent_id": "0",
"current_id": "2",
"children": [{
"power_id": "10",
"power_guid": "9cd32f9c-ab57-46e8-a8ac-f9cb1a7b7549",
"power_name": "会员资料维护",
"power_src": "",
"power_ico": "",
"power_description": "",
"power_index": "0",
"power_parentid": "2",
"power_deleted": "False",
"power_deletedtime": "",
"parent_id": "2",
"current_id": "10"
},
{
"power_id": "11",
"power_guid": "9cd32f9c-ab57-46e8-a8ac-f9cb1a7b7550",
"power_name": "充值记录消费管理",
"power_src": "",
"power_ico": "",
"power_description": "",
"power_index": "0",
"power_parentid": "2",
"power_deleted": "False",
"power_deletedtime": "",
"parent_id": "2",
"current_id": "11"
}]
}]
然后我拿着 我自己生成的 这段 json 和 easy ui demos 里的 treeGrid json.data 数据逐行对比,实在是找不出来为啥,麻烦路过的高手告诉我 是否还缺少一个什么属性来表示父子关系?万分感谢。
是不是你的css没有引用正确?
一般的JS的插件都是有写css文件的
应该不是,因为我把demos 中的代码复制到本页面上,引用css 和 js 的地方没有动过,可以正常显示。
看文档,格式是否正确
自己解决:
TreeGrid 需要一个 treeField ,这个字段指定为要显示树状的字段name即可。
这是easyUI的bug不是楼主的问题,没试过不要乱说,用JS动态加载出来的页面里只能用HTML形式去创建对象,用JS形式就会显示不正常了,不知道easyui新版本有没有修正了这个bug
楼主怎么解决的了?使用table的话,折叠怎么有空白了
treeField:'power_name'?
请问LZ 后来怎么解决的,我也遇到这个问题了
怎么解决的兄弟