easyUI的datagrid无法从后台加载数据
 <script type="text/javascript">

        var setting = {
            data: {
                simpleData: {
                    enable: true,
                    idKey:"id",
                    pIdKey:"pid"
                }
            },
            callback: {
                    onClick: zTreeOnClick
                }

        };


    $(function(){
        $.ajax({
                url:"<%=request.getContextPath() %>/getDeptTree.action",
                data:{},
                dataType:"json",
                type:"post",
                success:function(json){
                    $.fn.zTree.init($("#treeDemo"), setting, json);
                }
            });
    });
        function zTreeOnClick(event, treeId, treeNode) {

            var id = treeNode.id;
            var deptName = treeNode.name;
            alert(id+","+deptName);

            $("#dl").datagrid({    
                url:"<%=request.getContextPath()%>/getUserByDeptid.action?id="+id,
               columns:[[
                    {field:'id',title:'ID',width:100},
                    {field:'realname',title:'真实姓名',width:100},
                    {field:'loginname',title:'用户名',width:100},
                    {field:'asd',title:'职位',width:100},
                    {field:'mail',title:'邮箱',width:100},
                    {field:'sex',title:'性别',width:100},
                    {field:'tel',title:'电话',width:100},
                    {field:'qq',title:'QQ',width:100},
                    {field:'adddate',title:'入职日期',width:100},
                    {field:'lastlogin',title:'最后登录时间',width:100},
                    {field:'logintime',title:'访问次数',width:100},
                    {field:'caozuo',title:'操作',width:100}
                ]],
                fit:true,
                singleSelect:true 
            });  
        };
    </script>
  <div id="zuzhi" class="easyui-tabs" data-options="fit:true,border:false">   
    <div title="用户" style="display:none;">   
        <div id="用户" class="easyui-layout" data-options="fit:true">   
            <div data-options="region:'west',title:'部门结构',collapsible:true" style="width:150px;">
                <ul id="treeDemo" class="ztree">

                </ul>
            </div>   
            <div data-options="region:'center'" style="padding:5px;background:#eee;">
                <table  id="dl">   
                   <!-- <thead>   
                        <tr>   
                            <th data-options="field:'id',width:100">ID</th>   
                            <th data-options="field:'realname',width:100,editor:'text'">真实姓名</th>   
                            <th data-options="field:'loginname',width:100,editor:'text'">用户名</th>   
                            <th data-options="field:'asd',width:100,editor:'text'">职位</th>   
                            <th data-options="field:'mail',width:100,editor:'text'">邮箱</th>   
                            <th data-options="field:'sex',width:100,editor:'text'">性别</th>   
                            <th data-options="field:'tel',width:100,editor:'text'">电话</th>   
                            <th data-options="field:'qq',width:100,editor:'text'">QQ</th>   
                            <th data-options="field:'adddate',width:100,editor:'text'">入职日期</th>   
                            <th data-options="field:'lastlogin',width:100,editor:'text'">最后登录时间</th>   
                            <th data-options="field:'logintime',width:100,editor:'text'">访问次数</th>   
                            <th data-options="field:'caozuo',width:100">操作</th>   
                    </thead>  -->
                </table>  
            </div>   
        </div>    
    </div>
    <div title="权限" data-options="" style="display:none;">   
        权限    
    </div>   

    <div title="公司" data-options="" style="display:none;">   
        公司   
    </div>   


    <div title="动态" data-options="" style="display:none;">   
        动态    
    </div>  
</div>

大牛帮看看什么原因

3个回答

datagrid的getUserByDeptid.action都不进后台

判断初始化过就直接调用reload方法,而不是又重新执行一次构造

 var init=false;
function zTreeOnClick(event, treeId, treeNode) {

            var id = treeNode.id;
            var deptName = treeNode.name;
            alert(id+","+deptName);
if(init) $("#dl").datagrid('reload',url:"<%=request.getContextPath()%>/getUserByDeptid.action?id="+id);
else{
init=true;
            $("#dl").datagrid({    ............................

这种情况下建议把url("<%=request.getContextPath()%>/getUserByDeptid.action?id="+id)打印出来看下url有没有错误

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!