请教ztree问题, (着急), 谢谢您!!!!

u148 发布于 2013/01/05 14:30
阅读 981
收藏 0

@zTree 你好,想跟你请教个问题:有时间帮忙看下..谢谢您

zTree 中,默认选中上次的查询记录时为什么必须alert一次后才能选中??

js代码->>(红色字体是错误的地方)

function editUser(type){
    $('#sysUserTreeDiv').show();
    var systemMAType = "";
    if(type=='sys'){
     systemMAType = 1;
    }else if(type=='jf'){
     systemMAType = 2;
    }
    
    var setting = {
     async : {
      enable : true,
      url : "../user_getSysUser.so?systemMAType="+systemMAType
     },
     view: {
      selectedMulti: false
     },
     data: {
      simpleData: {
       enable: true,
       idKey: "id",
       pIdKey: "pid",
       rootPId: "0"
      }
     },
     check: {
      enable: true
     }
    };
    
    $('#sysUserTreeDiv').dialog({
     buttons:[{
      text:'确定',
      iconCls:'icon-ok',
      handler:function(){
       var treeObj = $.fn.zTree.getZTreeObj("sysUserTree");
       var userName="";
       var userId="";
       var nodes = treeObj.getCheckedNodes(true);
       for(var i=0;i<nodes.length;i++){
        if(nodes[i].pid!=0&&userId.indexOf(nodes[i].id)<0){
         userName=userName+nodes[i].name+";";
         userId=userId+nodes[i].id+";";
        }
       }
       if(type=='sys'){
        $("#sysUserName").val(userName);
        $("#sysUserID").val(userId);
       }else if(type=='jf'){
        $("#jfUserName").val(userName);
        $("#jfUserID").val(userId);
       }
       $('#sysUserTreeDiv').dialog('close');
      }
     },{
      text:'取消',
      icon:'icon-cancel',
      handler:function(){
       $('#sysUserTreeDiv').dialog('close');
      }
     }]
    });
    
    $.fn.zTree.init($("#sysUserTree"), setting, null);
    //======================
    if(type=='sys'){
                 var var_zTree = $.fn.zTree.getZTreeObj("sysUserTree");
               
             var sysUserIDs = $('#sysUserID').val();
             console.info(sysUserIDs);//这里没alert下边就没有执行
             var sysUserid;
            if(sysUserIDs!=null && sysUserIDs !='' && sysUserIDs.length!=0){
              sysUserid=sysUserIDs.split(';');
              
              for(var i =0,len=sysUserid.length;i<len;i++){
                var node = var_zTree.getNodeByParam("id", sysUserid[i], null);//得到选中节点
                   var_zTree.checkNode(node, true, true); //显示选中节点
                    var_zTree.selectNode(node); //打开选中节点的父节点
              }
              }
    }else if(type=='jf'){
     var var_zTree = $.fn.zTree.getZTreeObj("sysUserTree");
               
             var jfUserIDs = $('#jfUserID').val();
             alert(jfUserIDs);//这里必须alert
             var jfUserid;
            if(jfUserIDs!=null && jfUserIDs !='' && jfUserIDs.length!=0){
              jfUserid=jfUserIDs.split(';');
              
              for(var i =0,len=jfUserid.length;i<len;i++){
                var node = var_zTree.getNodeByParam("id", jfUserid[i], null);//得到选中节点
                   var_zTree.checkNode(node, true, true); //显示选中节点
                    var_zTree.selectNode(node); //打开选中节点的父节点
              }
              }
    
    }
    //======================
     
    var userId1="";
    if(type=='sys'){
     userId1 = $("#sysUserID").val();
    }else if(type=='jf'){
     userId1 = $("#jfUserID").val();
    }
    if(userId1 != ""){
     var userIdArr = userId1.split(";");
     var treeObj1 = $.fn.zTree.getZTreeObj("sysUserTree");
     var nodes1 = treeObj1.getNodes();
     for(var i=0;i<nodes1.length;i++){
      for(var j=0;j<userIdArr.length;j++){
       if(nodes1[i].id==userIdArr[j]){
        treeObj1.checkNode(nodes1[i], true, true);
       }
      }
     }
    }
   }

jsp代码片段

 

<tr>
	<td colspan="4">
		<table width="100%">
			<td width="15%">系统负责人:</td>
			<td width="75%">
				<input id="sysUserName" name="sysUserName" style="width:100%;"  class="easyui-validatebox"  required="true" readonly ></input>
				<input type="hidden" id="sysUserID" name="sysUserID">
			</td>
			<td width="10%"><a href="#" onclick="javascript:editUser('sys');" id="xtBianJi" icon="icon-edit">编辑</a></td>
		</table>
	</td>
</tr>
<tr>
	<td colspan="4">
		<table width="100%">
			<td width="15%">局方负责人:</td>
			<td width="75%">
				<input id="jfUserName" name="jfUserName" style="width:100%;"  class="easyui-validatebox"  required="true" readonly ></input>
				<input type="hidden" id="jfUserID" name="jfUserID" /> </td>
			<td width="10%"><a href="#" onclick="javascript:editUser('jf');" id="jfBianJi" icon="icon-edit">编辑</a></td>
		</table>
	</td>
</tr>

 

 图片->>

没有alert的没有选中

 

有alert的就选中了  很奇怪啊....

 

加载中
0
zTree
zTree
不奇怪,应该就是异步加载闹的,如果是自己哪里用了异步加载就要在 success之后进行处理,如果是需要等待节点异步加载完毕就要用ztree的onAsyncSuccess回调
0
u148
u148

谢谢您!  我解决了..

确实是需要加载完再调用onAsyncSuccess

不过我还有一个ztree的问题想问下您,能否留个邮箱,qq之类的联系方式.

0
AAAProcrastination
AAAProcrastination

引用来自“jorton”的评论

谢谢您!  我解决了..

确实是需要加载完再调用onAsyncSuccess

不过我还有一个ztree的问题想问下您,能否留个邮箱,qq之类的联系方式.

问下,我也碰到了这个问题,
treeObj.setting.callback.beforeClick(real_pid, node);//展开父节点
 var isSuccess = treeObj.setting.callback.onAsyncSuccess(null, real_pid, node, treeObj.getNodes());
                    alert(isSuccess);

我先展开父节点  那应该子节点就开始异步加载了   然后我调用 success函数  里面设了返回值  这里弹出返回值  才能执行下面的额 不然 子节点无法选中

你是怎么解决的
返回顶部
顶部