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

[Solved] How to tell if node is parent in javascript

2 Answers 155 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Donna Stewart
Top achievements
Rank 1
Donna Stewart asked on 13 Jan 2011, 04:19 AM
I am tring to loop through the checked items in my treeview and I need to know if the node is a parent or not.  This is on an image button click, not through a client event on the treeview.  I have tried every combination that I think might work to no avail  This is rather urgent and your help is very much appreciated!  Here is my javascript function:

function removeUsersFromGroups() {
    var grouptreeview = $('#UserGroupNames').data('tTreeView');
    var groupCheckedNodes = $('#UserGroupNames :checked').closest('.t-item');
    var groupsAndUsers = new Array();
    var grpUserKeys;
    var grpKey;
    $.each(groupCheckedNodes, function (node) {
        if (node.Parent() == null) {
            grpKey = grouptreeview.getitemValue(node);
        }
        else {
            grpUserKeys = { 'userKey': grouptreeview.getItemValue(node), 'groupKey': grpKey }
            groupsAndUsers.push(grpUserKeys);
        }
    });
    $.post("/User/RemoveUsersFromGroups", $.toJSON(groupsAndUsers), null, 'json');
}

Thank you,
Donna

2 Answers, 1 is accepted

Sort by
0
Accepted
Alex Gyoshev
Telerik team
answered on 13 Jan 2011, 09:03 AM
Hello Donna,

Please refer to the following code:

function removeUsersFromGroups() {
    var grouptreeview = $('#UserGroupNames').data('tTreeView'),
        groupsAndUsers = [], parent;
 
    $('#UserGroupNames :checked').closest('.t-item')
        .each(function (index, node) { // first arg: index, second arg: node
            parent = $(node).parent().closest('.t-item'); // get parent item
 
            if (!parent.length) { // if there is a parent item
                // add an object with only a groupKey
                groupsAndUsers.push({ 'groupKey': grouptreeview.getItemValue(node) });
            } else {
                // add an object with both a groupKey and userKey
                groupsAndUsers.push({ 'userKey': grouptreeview.getItemValue(node), 'groupKey': grouptreeview.getItemValue(parent) });
            }
        });
 
    $.post("/User/RemoveUsersFromGroups", $.toJSON(groupsAndUsers), null, 'json');
}

Greetings,
Alex Gyoshev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Donna Stewart
Top achievements
Rank 1
answered on 13 Jan 2011, 04:32 PM
Thank you, thank you, thank you!   You guys ROCK!
Tags
TreeView
Asked by
Donna Stewart
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Donna Stewart
Top achievements
Rank 1
Share this question
or