Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
595
Checked nodes all have the same 'data' instead of the object that relates to the specific node
posted

Basically, it doesn't matter which nodes I checked, every node in the checkedNodes array has the data corresponding to the first item in the data hierarchy. So if I've had the following tree data:

Grandparent
 - Parent
  - Child
  - Child

Then the data() of Parent and both Child nodes will be the data for the Grandparent node.

I am binding the tree data using knockout JS. I am using version 13.1.20131.2143, same issues occurs in Firefox, IE and Chrome.

This is my tree:


            <div id="selectorTree" data-bind="igTree: {
                dataSource: tree,
                width: '100%',
                initialExpandDepth: 999,
                checkboxMode: 'triState',
                bindings: {
                    textKey: 'text',
                    valueKey: 'value',
                    primaryKey: 'id',
                    imageUrlKey: 'imageUrl',
                    childDataProperty: 'children'
                }
            }">
            </div>

This is my model:

function Model() {
    var self = this;
    self.recipeTree = ko.observableArray([]);
}

These are the items I add to the tree:

function TreeNode(id, value, text) {
    var self = this;

    self.id = ko.observable(id);
    self.value = ko.observable(value);
    self.text = ko.observable(text);

    self.imageUrl = ko.computed(function () {
        return getNodeImageUrl(self.value());
    });

    self.children = ko.observableArray([]);
}


So when I want to get the values of my checked nodes

   var checkedNodes = $("#selectorTree").igTree("checkedNodes");

The Id is always 1 and the value is always the same as the top level node:

    for (var i = 0; i < checkedNodes.length; i++) {
        var node = checkedNodes[i];

        var id = node.data.id(); // Never changes
        var text = node.data.text(); // Never changes
       
    }