easyui treegrid的json数据格式是什么样的啊,燥死我了

 我来答
一骑当后
2014-11-19 · 知道合伙人数码行家
一骑当后
知道合伙人数码行家
采纳数:40298 获赞数:306435
网络、设备维护、电路、弱电检测。

向TA提问 私信TA
展开全部
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>TreeGrid - jQuery EasyUI Demo</title>
    <link rel="stylesheet" type="text/css" href="../themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../themes/icon.css">
    <link rel="stylesheet" type="text/css" href="demo.css">
    <script type="text/javascript" src="../jquery-1.6.min.js"></script>
    <script type="text/javascript" src="../jquery.easyui.min.js"></script>
    <script>
        $(function(){
            $('#test').treegrid({
                title:'TreeGrid',
                iconCls:'icon-save',
                width:700,
                height:350,
                nowrap: false,
                rownumbers: true,
                animate:true,
                collapsible:true,
                url:'treegrid_data.json',
                idField:'code',
                treeField:'code',
                 
                frozenColumns:[[
                    {title:'Code',field:'code',width:200,
                        formatter:function(value){
                            return '<span style="color:red">'+value+'</span>';
                        }
                    }
                ]],
                columns:[[
                    {field:'name',title:'Name',width:150},
                    {field:'addr',title:'Address',width:220,rowspan:2},
                    {field:'col4',title:'Col41',width:150,rowspan:2}
                ]],
                onBeforeLoad:function(row,param){
                    if (row){
                        $(this).treegrid('options').url = 'treegrid_subdata.json';
                    } else {
                        $(this).treegrid('options').url = 'treegrid_data.json';
                    }
                },
                onContextMenu: function(e,row){
                    e.preventDefault();
                    $(this).treegrid('unselectAll');
                    $(this).treegrid('select', row.code);
                    $('#mm').menu('show', {
                        left: e.pageX,
                        top: e.pageY
                    });
                }
            });
        });
 
        function reload(){
            var node = $('#test').treegrid('getSelected');
            if (node){
                $('#test').treegrid('reload', node.code);
            } else {
                $('#test').treegrid('reload');
            }
        }
        function getChildren(){
            var node = $('#test').treegrid('getSelected');
            if (node){
                var nodes = $('#test').treegrid('getChildren', node.code);
            } else {
                var nodes = $('#test').treegrid('getChildren');
            }
            var s = '';
            for(var i=0; i<nodes.length; i++){
                s += nodes[i].code + ',';
            }
            alert(s);
        }
        function getSelected(){
            var node = $('#test').treegrid('getSelected');
            if (node){
                alert(node.code+":"+node.name);
            }
        }
        function collapse(){
            var node = $('#test').treegrid('getSelected');
            if (node){
                $('#test').treegrid('collapse', node.code);
            }
        }
        function expand(){
            var node = $('#test').treegrid('getSelected');
            if (node){
                $('#test').treegrid('expand', node.code);
            }
        }
        function collapseAll(){
            var node = $('#test').treegrid('getSelected');
            if (node){
                $('#test').treegrid('collapseAll', node.code);
            } else {
                $('#test').treegrid('collapseAll');
            }
        }
        function expandAll(){
            var node = $('#test').treegrid('getSelected');
            if (node){
                $('#test').treegrid('expandAll', node.code);
            } else {
                $('#test').treegrid('expandAll');
            }
        }
        function expandTo(){
            $('#test').treegrid('expandTo', '02013');
            $('#test').treegrid('select', '02013');
        }
        var codeIndex = 1000;
        function append(){
            codeIndex++;
            var data = [{
                code: 'code'+codeIndex,
                name: 'name'+codeIndex,
                addr: 'address'+codeIndex,
                col4: 'col4 data'
            }];
            var node = $('#test').treegrid('getSelected');
            $('#test').treegrid('append', {
                parent: (node?node.code:null),
                data: data
            });
        }
        function remove(){
            var node = $('#test').treegrid('getSelected');
            if (node){
                $('#test').treegrid('remove', node.code);
            }
        }
    </script>
</head>
<body>
    <h2>TreeGrid</h2>
    <div class="demo-info">
        <div class="demo-tip icon-tip"></div>
        <div>Combines treeview and datagrid to represent hierarchical data.</div>
    </div>
     
    <div style="margin:10px 0;">
        <a href="#" onclick="reload()">Reload</a>
        <a href="#" onclick="getChildren()">GetChildren</a>
        <a href="#" onclick="getSelected()">GetSelected</a>
        <a href="#" onclick="collapse()">Collapse</a>
        <a href="#" onclick="expand()">Expand</a>
        <a href="#" onclick="collapseAll()">CollapseAll</a>
        <a href="#" onclick="expandAll()">ExpandAll</a>
        <a href="#" onclick="expandTo()">ExpandTo</a>
        <a href="#" onclick="append()">Append</a>
    </div>
     
    <table id="test"></table>
     
    <div id="mm" class="easyui-menu" style="width:120px;">
        <div onclick="append()">Append</div>
        <div onclick="remove()">Remove</div>
    </div>
</body>
</html>

官方API

秒懂百科
2021-04-14 · TA获得超过5.9万个赞
知道大有可为答主
回答量:25.3万
采纳率:88%
帮助的人:1.2亿
展开全部

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式