1

I have a kendo tree and am trying to bind it to a hierarchichal datasource which comes from my controller. But only the most parent item is showing in the tree and no child items are shown. I tried multiple approaches suggested but no luck :(. Please find the code below and please help.

function populateTreeView() {
    var remoteDataSource = new kendo.data.HierarchicalDataSource({
        transport: {
            read: {
                url: "@Url.Action("GetRoot", "OrgUnit")",
                dataType: "json",
                type: "GET",

            }
         },
        schema: {

            model: {
                id: "id",
                text: "label",
                expanded: true,
                children: "children",
                hasChildren: "HasChildren"
            },
        }
    });

    $("#org-tree1").kendoTreeView({
        dataSource: remoteDataSource,
        dataTextField: "label"
    });
}

$(document).ready(function () {


    populateTreeView();

});

and My controller returns

var model = new List {root};

        return Json(model, JsonRequestBehavior.AllowGet);

My OrgUnit Model looks like

public class OrgUnitModel { private List child = new List();

    public int OrgUnitID { get; set; }
    public string OrgUnitName { get; set; }
    public OrgUnitTypes OrgUnitType { get; set; }
    public bool Active { get; set; }
    public bool HasChildren { get { return children.Count > 0; } set { } }
    public List<OrgUnitModel> children { get { return child; } set { child = value; } }

    //Added for the Json
    public string label
    {
        get
        {
            return OrgUnitName;
        }
        set
        {
        }
    }

    public bool load_on_demand
    {
        get { return true; }
    }

    public int id
    {
        get { return OrgUnitID; }
        set { }
    }
}

Thanks in advance

4

0 回答 0