有隐式类型数组要发送到 jsTree:
var first = new[]
{
new
{
id = "Root " + i.ToString(),
text = "Root Node " + i.ToString(),
state = new
{
opened = true,
},
children = new[]
{
new
{
id = "Child " + gc1,
text = "Child " + gc1,
children = true
},
new
{
id = "Child " + gc2,
text = "Child " + gc2,
children = true
}
}
}
}
.ToList();
但是当我尝试在上面的代码中声明子级并将其添加到第一个父级时,它不起作用:
var child = new[]
{
new
{
id = "Child " + gc1,
text = "Child " + gc1,
children = true
}
}
.ToArray();
var first = new[]
{
new
{
id = "Root " + i.ToString(),
text = "Root Node " + i.ToString(),
state = new
{
opened = true,
},
children = new[]
{
child
}
}
}
.ToList();
我做错了什么,为什么jsTree在这种情况下不显示孩子?
谢谢!!!
我尝试比较两个 JsonResults,它似乎是相同的......
添加两个类有助于解决这个问题:
public class rodic
{
public string id { get; set; }
public string text { get; set; }
public string icon { get; set; }
public object state { get; set; }
public List<decko> children { get; set; }
}
public class decko
{
public string id { get; set; }
public string text { get; set; }
public string icon { get; set; }
public object state { get; set; }
public bool children { get; set; }
}
然后
nodesDecko.Add(new decko { id = dite.id, text = dite.text, icon=ikonaDite, children = dite.children });
nodesRodic.Add(new rodic { id = objectKey.ToString(), text = objectKey + " " + "[" + objectType + "] " + nameJIRA, icon = "/images/icons/" + iconName, state = new { opened = true }, children = nodesDecko });