Private list<model.organization.organization> getorganiztions ()
{
var organizations = new list<model.organization.organization> ();
Organizations. ADD (New Model.Organization.Organization
{
Id = "1",
Name = "FAW",
});
Organizations. ADD (New Model.Organization.Organization
{
Id = "2",
Name = "Red Flag",
ParentID = "1"
});
Organizations. ADD (New Model.Organization.Organization
{
Id = "3",
Name = "Pentium",
ParentID = "1"
});
Organizations. ADD (New Model.Organization.Organization
{
Id= "4",
Name= "Pentium B70",
Parentid= "3"
});
return organizations;
}
private void Attachchildren (TreeModel tree, list<model.organization.organization> organizations)
{
if (Equals (tree, NULL))
{
Return
}
var organizationstmp = organizations. Where (p = =!string. IsNullOrEmpty (P.parentid) && p.parentid.equals (tree.id)). ToList ();
foreach (Model.Organization.Organization node in organizationstmp)
{
var t = new TreeModel () {
Id=node. Id
Text=node. Name
};
TREE.CHILDREN.ADD (t);
This. Attachchildren (T, organizations);
}
}
Public ilist<treemodel> Gettree ()
{
var organizations = this. Getorganiztions ();
var RootNode = organizations. Find (P. = String. IsNullOrEmpty (P.parentid));
var tree = new TreeModel ()
{
id = rootnode.id,
Text = Rootnode.name
};
This. Attachchildren (tree, organizations);
return new list<treemodel> () {tree};
}
If Gettree returns a collection, the Controler call Gettree is serialized as JSON after:
[{"id": "1", "Text": "Faw", "Children": [{"id": "2", "Text": "Red Flag", "Children": []},{"id": "3", "text": "Pentium", "children": [{"id ":" 4 "," Text ":" Pentium B70 "," Children ": []}]}]
If Gettree returns an object, the Controler call Gettree is serialized as JSON after:
{"id": "1", "Text": "Faw", "Children": [{"id": "2", "Text": "Red Flag", "Children": []},{"id": "3", "text": "Pentium", "children": [{"id" : "4", "Text": "Pentium B70", "Children": []}]}]}
In the front-end of ASP. We may often use JSON arrays, we can consider the use of JSON (collection) way, so that can not be processed at the front end