【发布时间】:2018-10-22 15:27:35
【问题描述】:
我在 ui 中显示 jstree 并用 asp.net 服务器端代码中的 json 填充它,它工作得很好,但是当我有一个节点和两个父节点时,它不能很好地工作。 我可以显示一个节点和两个父节点的 jstree 吗? 当我这样做时,它会显示错误。 两个父母之间的孩子! 我知道它不是树角色,但我需要它。
$(function () {
$('#jstree').jstree({
'core': {
"animation": 0,
"check_callback": true,
"themes": { "stripes": true },
'data': {
'url': '/Products/ProductCategoryStructure/GetData',
'data': function (node) {
return { 'id': node.id };
}
}
},
"types": {
"#": {
"max_children": 1,
"max_depth": 4,
"valid_children": ["root"]
},
"default": {
"valid_children": ["default", "file"]
},
"file": {
"icon": "glyphicon glyphicon-file",
"valid_children": []
}
},
plugins: ["contextmenu"], contextmenu: {items: customMenu}
});
$('#jstree').on('changed.jstree', function (e, data) {
var i, j, r = [];
for (i = 0, j = data.selected.length; i < j; i++) {
r.push(data.instance.get_node(data.selected[i]).text);
}
//alert('Selected: ' + r.join(', '));
// $('#event_result').html('Selected: ' + r.join(', '));
}).jstree();
});
这是服务器端代码
[HttpGet]
public ActionResult GetData()
{
var ListProductCategoryStructure = _service.GetAll();
var nodes = new List<JsTreeModel>();
//nodes.Add(new JsTreeModel() { id = "58", parent = "#", text = " مادیران مال",opened=true,icon="/assets/pages/img/mlgo.png" });
nodes.Add(new JsTreeModel() { id = "1", parent = "#", text = " مادیران مال", opened = true, icon = "/assets/pages/img/mlgo.png" });
foreach (var item in ListProductCategoryStructure)
{
nodes.Add(new JsTreeModel() { id = item.ProductCategoryId.ToString(), parent = (item.ProductParentCategoryId==65?"#": item.ProductParentCategoryId.ToString()), text = item.ProductParentCategoryTitle,icon="false" });
}
return Json(nodes, JsonRequestBehavior.AllowGet);
}
【问题讨论】:
标签: html asp.net json tree jstree