ztree吧 关注:1,835贴子:12,478
  • 7回复贴,共1

如何动态设置setting.check.chkStyle的值

只看楼主收藏回复

//配置信息
var setting = {
data: {
simpleData: {enable: true,idKey: "id",pIdKey: "pId",rootPId: 0}
},
check: {
enable: true,
chkStyle: "radio",
//chkStyle:function(){if($("#multiSelect").val() == "0"){return "radio";}else{return "checkbox";}},
radioType: "all"
}
};
-----------------------------------------------------------
setting.check.chkStyle是用来决定是单选还是多选的
我想在树加载前动态生成它的值(radio/checkbox),而不是像chkStyle: "radio"这样写死
就是根据URL&multiSelect=0中multiSelect的值是0还是1来决定树节点是单选还是多选
该怎么实现动态设置chkStyle的值?
我注释掉的那行代码是无效的......


IP属地:广西1楼2014-12-02 08:59回复
    不好意思,已经自己搞定了
    //初始化树
    function initTree()
    {
    multiSelect = $("#multiSelect").val();
    if(multiSelect=="1"){setting.check.chkStyle="checkbox";}
    $.fn.zTree.init($("#ztree"), setting,null);
    zTree = $.fn.zTree.getZTreeObj("ztree");
    }


    IP属地:广西2楼2014-12-02 09:38
    回复
      setting师哥json对象,你在var treeObj = $.fn.zTree.init($("#earaTree"), allAreaSetting,result);之前修改里面的值就可以了;例子如下:
      var setting = {
      data: {
      simpleData: {enable: true,idKey: "id",pIdKey: "pId",rootPId: 0}
      },
      check: {
      enable: true,
      chkStyle: "radio",
      //chkStyle:function(){if($("#multiSelect").val() == "0"){return "radio";}else{return "checkbox";}},
      radioType: "all"
      }
      };
      //从后台获取json对象后:
      //从后台获取数据 显示树
      function init() {
      $.ajax({
      cache : false,
      asunc:false,
      type : "post",
      dataType : "json",
      url : projectName + "/area/getCurrUserAllArea",
      success : function(result) {
      console.info("get area tree success");
      if (result == null || result == '') {
      $("#earaTree").html("暂无数据");
      } else {
      // treeNode = result;
      var multiSelect = 0; //从页面获取
      if (multiSelect==1) {
      setting .check.chkStyle = "checkbox";
      } else{
      setting .check.chkStyle = "radio";
      };
      var treeObj = $.fn.zTree.init($("#earaTree"), setting ,result);
      }
      }
      });
      }


      IP属地:四川3楼2014-12-02 09:46
      收起回复
        async: {
        enable: true,
        type: "post",
        url: "/homepage.nsf/ajaxGetTreeNodesInfoForSelect?openAgent",
        dataType: "json",
        autoParam:["id=pId"]
        //,otherParam:{"curUserName":function(){return curUserName;}}
        }
        --------------------
        上面注释那行是可以的


        IP属地:广西4楼2014-12-02 09:52
        收起回复