Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when using 'children' but not 'parent' property in json model for jstree pushing to tree model doesn't update the jstree view #47

Open
maksfastovets opened this issue Nov 4, 2015 · 5 comments

Comments

@maksfastovets
Copy link

Hi!

When I use json data for jsTree with children but without parent, like this:

{
  id          : "string" // will be autogenerated if omitted
  text        : "string" // node text
  icon        : "string" // string for custom
  state       : {
    opened    : boolean  // is the node open
    disabled  : boolean  // is the node disabled
    selected  : boolean  // is the node selected
  },
  children    : []  // array of strings or objects
  li_attr     : {}  // attributes for the generated LI node
  a_attr      : {}  // attributes for the generated A node
} // note there is no parent property in this json

-- then pushing to ngJsTree's model doesn't rerender jsTree view. Incrementing version will do the trick, but I don't want to rerender whole tree if only one node is added.

I noticed that you use following code to add to the jsTree's model newly pushed node:

...
var parent = scope.tree.jstree(true).get_node(node.parent);
var res = scope.tree.jstree(true).create_node(parent, node, 'inside',function() {
...

-- so if node doesn't have parent property (as in my case) node wont' be added/

Using both children and parent at the same time is impossible (https://www.jstree.com/docs/json/) as jstree prefers parent and ignores children as far as I understand.

@ezraroi
Copy link
Owner

ezraroi commented Nov 5, 2015

will check this week

@maksfastovets
Copy link
Author

Thanks!
And one more thing. Your method:

var getTokens = function () {
    var result = [], token, el;
    if (arraySource) {
        var array = angular.isFunction(arraySource) ? arraySource() : arraySource;
        for (var i = 0, n = array.length; i < n; i++) {
            el = array[i];
            token = tokenFn(el);
            map[token] = el;
            result.push(token);
        }
    }
    return result;
};

which is used to watch model changes watches only first-level elements (doesn't take 'children' property into account).

@ezraroi
Copy link
Owner

ezraroi commented Nov 5, 2015

Yes, because in the other syntax (the parent one), all are first level.
From what i saw, there is not create_node function in the jsTree that doesn't require parent node. Looks like to support this data format i will need to change many things, not sure i will have time soon. Sorry, you are welcome to fork and pr :)

@maksfastovets
Copy link
Author

ok, got it, thanks for your quick reply :)

@LorandLorincz
Copy link

+1. would need this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants