问题描述
- 在三层加.net mvc4.0 中使用ztree显示分类时为什么得到的显示效果是undefined
-
我Controller中的代码如下:
public ActionResult LoadAllCat()
{
List list = null;
list = new List();
List lists = categoryService.GetCategory();
foreach (var listcat in lists)
{
Category category = new Category();
category.Id = listcat.Id;
category.ParentsId = listcat.ParentsId;
category.CategoryName = listcat.CategoryName;
list.Add(category);
}
//JavaScriptSerializer jss = new JavaScriptSerializer();
//string ResultDt = jss.Serialize(list);
//return ResultDt;
return Json(list, JsonRequestBehavior.AllowGet);
}
Index.cshtml代码如下:
var setting = {
check: {
enable: true
},
//chkboxType: { "Y": "ps", "N": "ps" },//默认这个
data: {
simpleData: {
enable: true,
idKey: "Id", // id编号命名
pIdKey: "ParentsId", // 父id编号命名
rootPId: 0
}
},
async: {
enable: true,
contentType: "application/json",
dataType: "text",
url: "/CategoryList/LoadAllCat",
type:"GET",
autoParam: ["Id", "CategoryName","ParentsId"]
}
};
function checkNode(e) {
var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
type = e.data.type,
nodes = zTree.getSelectedNodes();
if (type.indexOf("All") < 0 && nodes.length == 0) {
alert("请先选择一个节点");
}
if (type == "checkAllTrue") {
zTree.checkAllNodes(true);
} else if (type == "checkAllFalse") {
zTree.checkAllNodes(false);
}
}
$(document).ready(function () {
$.fn.zTree.init($("#treeDemo"), setting);
$("#checkAllTrue").bind("click", { type: "checkAllTrue" }, checkNode);
$("#checkAllFalse").bind("click", { type: "checkAllFalse" }, checkNode);
});
//-->
时间: 2024-11-02 07:34:33