private void CreateTreeScript() { string treeID = this.ID; StringBuilder sb = new StringBuilder(); sb.AppendLine(""); sb.Append("$(function(){"); #region 生成节点数据 if (this.DataSource != null) { this.SimpleData.Enable = true; foreach (DataRow row in this.DataSource.Rows) { TreeItem node = new TreeItem(); node.ID = row[this.SimpleData.IDKey].ToString(); node.PID = row[this.SimpleData.PIDKey].ToString(); node.Text = row[this.SimpleData.TextField].ToString(); if (!string.IsNullOrEmpty(this.SimpleData.ValueField)) { node.Value = row[this.SimpleData.ValueField].ToString(); } if (this.SimpleData.AttributeFields.Count > 0) { foreach (string key in this.SimpleData.AttributeFields.Keys) { node.Attributes.Add(this.SimpleData.AttributeFields[key], row[key]); } } this.Items.Add(node); } } if (this.Items.Count > 0) { sb.Append("var data=" + ZTreeMgr.GetzTreeData(this.Items) + ";"); } else { sb.Append("var data=null;"); } sb.AppendLine(""); #endregion //生成配置参数选项 sb.Append("var setting={"); //sb.Append("treeId:\""+this.ID+"\","); #region 配置视图参数 sb.Append("view:{"); sb.Append("selectedMulti:" + WSH.Web.Common.Helper.ClientHelper.GetBool(this.View.SelectedMulti)); if (this.View.SelectedMulti) { this.View.AutoCancelSelected = true; } sb.Append(",autoCancelSelected:" + WSH.Web.Common.Helper.ClientHelper.GetBool(this.View.AutoCancelSelected)); if (!this.View.ShowLine) { sb.Append(",showLine:false"); } if (!this.View.ShowIcon) { sb.Append(",showIcon:false"); } if (!this.View.ShowTitle) { sb.Append(",showTitle:false"); } if (!this.View.DblClickExpand) { sb.Append(",dblClickExpand:false"); } if (this.View.FontCss.Count > 0) { sb.Append(",fontCss:" + WSH.Web.Common.Helper.ClientHelper.GetDictionary(this.View.FontCss)); } if (!string.IsNullOrEmpty(this.View.AddDiyDom)) { sb.Append(",addDiyDom:" + this.View.AddDiyDom); } if (!string.IsNullOrEmpty(this.View.AddHoverDom)) { sb.Append(",addHoverDom:" + this.View.AddHoverDom); } if (!string.IsNullOrEmpty(this.View.RemoveHoverDom)) { sb.Append(",removeHoverDom:" + this.View.RemoveHoverDom); } sb.Append("}"); #endregion #region 配置异步参数 if (this.Async.Enable) { sb.Append(",async:{"); sb.Append("enable:" + WSH.Web.Common.Helper.ClientHelper.GetBool(Async.Enable)); sb.Append(",dataType:\"" + WSH.Web.Common.Helper.ClientHelper.GetEnum(Async.DataType) + "\""); if (!string.IsNullOrEmpty(Async.DataFilter)) { sb.Append(",dataFilter:\"" + Async.DataFilter + "\""); } if (Async.AutoParam != null) { sb.Append(",autoParam:" + WSH.Web.Common.Helper.ClientHelper.GetArray(Async.AutoParam)); } if (Async.OtherParam.Count > 0) { sb.Append(",otherParam:" + WSH.Web.Common.Helper.ClientHelper.GetDictionary(Async.OtherParam)); } sb.Append(",url:\"" + Async.Url + "\""); sb.Append(",type:\"" + Async.Type.ToString().ToLower() + "\""); sb.Append("}"); } #endregion #region 配置选择参数 if (this.Check.Enable) { sb.Append(",check:{"); sb.Append("enable:" + WSH.Web.Common.Helper.ClientHelper.GetBool(this.Check.Enable)); sb.Append(",chkStyle:\"" + WSH.Web.Common.Helper.ClientHelper.GetEnum(this.Check.CheckStyle) + "\""); if (this.Check.CheckStyle == CheckStyle.Radio) { sb.Append(",radioType:\"" + WSH.Web.Common.Helper.ClientHelper.GetEnum(this.Check.RadioType) + "\""); } else { sb.Append(",chkboxType:" + (this.Check.TwoWay ? "{Y:\"ps\",N:\"ps\"}" : "{Y:\"\",N:\"\"}")); } sb.Append("}"); } #endregion #region 配置客户端的回调函数 sb.Append(",callback:{"); //首先配置单击回调函数 sb.Append("onClick:" + (string.IsNullOrEmpty(OnClick) ? "null" : OnClick)); #region 配置Before回调 if (!string.IsNullOrEmpty(BeforeAsync)) { sb.Append(",beforeAsync:" + BeforeAsync); } if (!string.IsNullOrEmpty(BeforeCheck)) { sb.Append(",beforeCheck:" + BeforeCheck); } if (!string.IsNullOrEmpty(BeforeClick)) { sb.Append(",beforeClick:" + BeforeClick); } if (!string.IsNullOrEmpty(BeforeCollapse)) { sb.Append(",beforeCollapse:" + BeforeCollapse); } if (!string.IsNullOrEmpty(BeforeDblClick)) { sb.Append(",beforeDblClick:" + BeforeDblClick); } if (!string.IsNullOrEmpty(BeforeDrag)) { sb.Append(",beforeDrag:" + BeforeDrag); } if (!string.IsNullOrEmpty(BeforeDragOpen)) { sb.Append(",beforeDragOpen:" + BeforeDragOpen); } if (!string.IsNullOrEmpty(BeforeDrop)) { sb.Append(",beforeDrop:" + BeforeDrop); } if (!string.IsNullOrEmpty(BeforeExpand)) { sb.Append(",beforeExpand:" + BeforeExpand); } if (!string.IsNullOrEmpty(BeforeMouseDown)) { sb.Append(",beforeMouseDown:" + BeforeMouseDown); } if (!string.IsNullOrEmpty(BeforeMouseUp)) { sb.Append(",beforeMouseUp:" + BeforeMouseUp); } if (!string.IsNullOrEmpty(BeforeRemove)) { sb.Append(",beforeRemove:" + BeforeRemove); } if (!string.IsNullOrEmpty(BeforeRename)) { sb.Append(",beforeRename:" + BeforeRename); } if (!string.IsNullOrEmpty(BeforeRightClick)) { sb.Append(",beforeRightClick:" + BeforeRightClick); } #endregion #region 配置On回调 if (!string.IsNullOrEmpty(OnAsyncError)) { sb.Append(",onAsyncError:" + OnAsyncError); } if (!string.IsNullOrEmpty(OnAsyncSuccess)) { sb.Append(",onAsyncSuccess:" + OnAsyncSuccess); } if (!string.IsNullOrEmpty(OnCheck)) { sb.Append(",onCheck:" + OnCheck); } if (!string.IsNullOrEmpty(OnCollapse)) { sb.Append(",onCollapse:" + OnCollapse); } if (!string.IsNullOrEmpty(OnDblClick)) { sb.Append(",onDblClick:" + OnDblClick); } if (!string.IsNullOrEmpty(OnDrag)) { sb.Append(",onDrag:" + OnDrag); } if (!string.IsNullOrEmpty(OnDrop)) { sb.Append(",onDrop:" + OnDrop); } if (!string.IsNullOrEmpty(OnExpand)) { sb.Append(",onExpand:" + OnExpand); } if (!string.IsNullOrEmpty(OnMouseDown)) { sb.Append(",onMouseDown:" + OnMouseDown); } if (!string.IsNullOrEmpty(OnMouseUp)) { sb.Append(",onMouseUp:" + OnMouseUp); } if (!string.IsNullOrEmpty(OnNodeCreated)) { sb.Append(",onNodeCreated:" + OnNodeCreated); } if (!string.IsNullOrEmpty(OnRemove)) { sb.Append(",onRemove:" + OnRemove); } if (!string.IsNullOrEmpty(OnRename)) { sb.Append(",onRename:" + OnRename); } if (!string.IsNullOrEmpty(OnRightClick)) { sb.Append(",onRightClick:" + OnRightClick); } #endregion sb.Append("}"); #endregion #region 配置编辑功能参数 if (this.Edit.Enable) { sb.Append(",edit:{"); sb.Append("enable:" + WSH.Web.Common.Helper.ClientHelper.GetBool(this.Edit.Enable)); sb.AppendFormat(",removeTitle:\"{0}\"", this.Edit.RemoveTitle); sb.AppendFormat(",renameTitle:\"{0}\"", this.Edit.RenameTitle); if (!this.Edit.ShowRemoveBtn) { sb.Append(",showRemoveBtn=false"); } if (!this.Edit.ShowRenameBtn) { sb.Append(",showRenameBtn=false"); } #region 配置拖动功能参数 sb.Append(",drag:{"); sb.Append("isCopy:" + WSH.Web.Common.Helper.ClientHelper.GetBool(this.Drag.IsCopy)); sb.Append(",isMove:" + WSH.Web.Common.Helper.ClientHelper.GetBool(this.Drag.IsMove)); if (this.Drag.IsMove || this.Drag.IsCopy) { if (!this.Drag.Prev) { sb.Append(",prev:false"); } if (!this.Drag.Next) { sb.Append(",next:false"); } if (!this.Drag.Inner) { sb.Append(",inner:false"); } sb.Append(",maxShowNodeNum:" + this.Drag.MaxShowNodeNum.ToString()); } sb.Append("}"); #endregion sb.Append("}"); } #endregion sb.Append("};"); sb.AppendLine(""); sb.AppendLine("var " + treeID + "=song.ztree.init($(\"#" + this.ClientID + "\"),setting,data);"); sb.AppendLine("});"); Script.RegisterStartupScript(this.Page, "ZTree-" + this.ID, sb.ToString()); }
public static string GetzTreeItemData(TreeItem node) { StringBuilder sb = new StringBuilder(); sb.Append("{"); sb.Append("\"name\":\"" + node.Text + "\""); sb.Append(",\"open\":" + node.IsOpen.ToString().ToLower()); if (!string.IsNullOrEmpty(node.ID)) { sb.Append(",\"id\":\"" + node.ID + "\""); } if (!string.IsNullOrEmpty(node.PID)) { sb.Append(",\"pid\":\"" + node.PID + "\""); } if (!string.IsNullOrEmpty(node.Value)) { sb.Append(",\"value\":\"" + node.Value + "\""); } if (node.Attributes.Count > 0) { foreach (string key in node.Attributes.Keys) { object value = node.Attributes[key]; if (DataTypeHelper.IsBool(value)) { sb.AppendFormat(",\"{0}\":{1}", key, value); } else { sb.AppendFormat(",\"{0}\":\"{1}\"", key, value); } } } if (node.IsChecked.HasValue) { sb.Append(",\"checked\":" + node.IsChecked.ToString().ToLower()); } if (node.NoCheck.HasValue) { sb.Append(",\"nocheck\":" + node.NoCheck.ToString().ToLower()); } if (node.IsLeaf.HasValue) { sb.Append(",\"isParent\":" + (!node.IsLeaf).ToString().ToLower()); } if (!string.IsNullOrEmpty(node.Icon)) { sb.Append(",\"icon\":\"" + node.Icon + "\""); } if (!string.IsNullOrEmpty(node.IconOpen)) { sb.Append(",\"iconOpen\":\"" + node.IconOpen + "\""); } if (!string.IsNullOrEmpty(node.IconClose)) { sb.Append(",\"iconClose\":\"" + node.IconClose + "\""); } if (!string.IsNullOrEmpty(node.IconClass)) { sb.Append(",\"iconSkin\":\"" + node.IconClass + "\""); } if (!string.IsNullOrEmpty(node.Target)) { sb.Append(",\"target\":\"" + node.Target + "\""); } if (!string.IsNullOrEmpty(node.Url)) { sb.Append(",\"url\":\"" + node.Url + "\""); } if (node.Items.Count > 0) { sb.Append(",\"children\":"); sb.Append(GetzTreeData(node.Items)); } sb.Append("}"); return(sb.ToString()); }