This is a migrated thread and some comments may be shown as answers.

Load on demand - Error: property 'length' is not defined

1 Answer 36 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Amit
Top achievements
Rank 1
Amit asked on 12 May 2014, 08:58 PM
Hello,

I am trying to load the children of node when the user expands the node in an MVC 4 application. The razor and controller  code is below -
I get an error about a length property not found at the line -         treeview.append(result, node);
Error
(window.kendo.jQuery);(function(e,t){function n(e){return function(t){var n=t.children(".k-animation-container");return n.length||(n=t),n.children(e)

Thanks in advance,

Amit

<script type="text/javascript">
    function loadChildrenForEntity(entityId) {

        dataSource = new kendo.data.HierarchicalDataSource({
            transport: {
                read: {
                    cache: false,
                    url: "@Url.Action("GetChildrenForEntity", "Admin")",
                    dataType: "json",
                    data: function () {
                        return {
                            entityID: entityId
                        };
                    }
                }
            },
            schema: {
                model: {
                    id: "ItemHID",
                    hasChildren: "HasChildren"
                }
            }
        });

        $("#entityDetails").kendoTreeView({
            dataSource: dataSource,
            //            select: onSelect,
            expand: onExpand,
            dataTextField: "DisplayName"
        }).data("kendoTreeView");
    }

    function onExpand(e) {
        var treeview = $('#entityDetails').data('kendoTreeView');
        var node = e.node;
        var data = treeview.dataItem(node);
        //alert('id = ' + data.id);
        $.ajax({
            url: "@Url.Action("GetChildrenForEntity", "Admin")",
            //type: "POST",
            datatype: "json",
            data: { entityID: data.id },
            success: function (result) {
                DisplayChildNodes(result, node)
            }
        });
    }

    function DisplayChildNodes(result, node) {
        var treeview = $('#entityDetails').data('kendoTreeView');
        treeview.append(result, node);
    }
</script>

The code in the controller is -
        public ActionResult Detail()
        {
            return PartialView();
        }

        public ActionResult GetChildrenForEntity(int entityID)
        {
            //entityID = -1000001;
            List<EntityTreeItem> list;
            list = new FDCRouteServiceClient().ListChildrenForEntity(entityID);
            var returnList = list.Select(r =>
                new RouteTreeViewModel
                {//todo - amit k - have RouteTreeViewModel derive from a base class EntityTreeViewModelBase
                    DisplayName = string.Format("{0} ({1})", r.EntName, r.EntTypeName),
                    ItemHID = r.EntHID,
                    //ParentHID = entityID,
                    HasChildren = r.HasChildren.Equals("1") ? true : false,
                    //ItemTypeCode = r.ItemTypeCode.Trim(),
                    //RouteHID = r.RouteHID,
                    //ParentTypeCode = r.ParentTypeCode
                }).ToList();

            return Json(returnList, JsonRequestBehavior.AllowGet);
        }

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 14 May 2014, 04:18 PM
Hello Amit,

The append method of the TreeView is designed to append a single node. From your code it seems that you are trying to append multiple items which is not supported.

Instead please consider using the build-in remote binding of the Hierarchical DataSource component. For more information check the following help topics:

Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
TreeView
Asked by
Amit
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or