This is a migrated thread and some comments may be shown as answers.
DataSource of Undefined
1 Answer 202 Views
This is a migrated thread and some comments may be shown as answers.
Mohammad Reza
Top achievements
Rank 1
Mohammad Reza asked on 25 Nov 2017, 12:38 PM
hi
in need help to fix error this function
this error show me in console
Uncaught TypeError: Cannot read property 'dataSource' of undefined


function treeview_getCheckedItems(treeId) {
    function _checkedNodeIds(nodes, checkedNodes) {
        for (var i = 0; i < nodes.length; i++) {
            if (nodes[i].checked) {
                checkedNodes.push(nodes[i]);
            }

            if (nodes[i].hasChildren) {
                _checkedNodeIds(nodes[i].children.view(), checkedNodes);
            }
        }
    }
    var treeView = $("#" + treeId).data("kendoTreeView");
    var treeData = treeView.dataSource.view();
    var checkedNodes = [];
    _checkedNodeIds(treeData, checkedNodes);
    return checkedNodes;
}

1 Answer, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 28 Nov 2017, 03:25 PM
Hi,

Assuming you get this exception when this line is executed:
var treeData = treeView.dataSource.view();

this means you don't have a proper reference to the TreeView. This could be due to passing an incorrect id value here:
var treeView = $("#" + treeId).data("kendoTreeView");
so we can suggest checking whether an element with this id exist by the time you are trying to access it: $("#" + treeId)

If you post a runnable dojo example, which demonstrates the issue we would be able to inspect your code and check why the treeView variable does not hold a valid reference to the widget.

Regards,
Ivan Danchev
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Asked by
Mohammad Reza
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Share this question
or