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

Unable to asynchronously load #7

Closed
christophla opened this issue Oct 30, 2014 · 19 comments
Closed

Unable to asynchronously load #7

christophla opened this issue Oct 30, 2014 · 19 comments
Assignees

Comments

@christophla
Copy link

I am unable to get the tree to load data from an async promise. Is there a way to force the tree to render once the ng-model has changed?

@ezraroi
Copy link
Owner

ezraroi commented Oct 30, 2014

Hi,
can you write a plunker with the code? basically you don't have to force, the update should happen automatically. You can look on the demo code for example. Are you using $http to load the data async?

@christophla
Copy link
Author

I’m using typescript and rectangular (repository). The data.industryHierarchy contains the array of valid nodes. I’m also using the child array approach (versus the parent id).

repositories.industryHierarchy.search($scope.query, IndustryClassification.Any).then(function (data) {
$scope.loading = false
$scope.treeData = data.industryHierarchy
}, function (response) {
$scope.loading = false
$scope.errormessage = response.data.message
services.logger.error('An error occurred searching', response.data)
})

On Oct 30, 2014, at 4:40 PM, Roi Ezra notifications@github.com wrote:

Hi,
can you write a plunker with the code? basically you don't have to force, the update should happen automatically. You can look on the demo code for example. Are you using $http to load the data async?


Reply to this email directly or view it on GitHub #7 (comment).

@christophla
Copy link
Author

If I manually drop in the array, I can see that it supports the parent / child array format.

@ezraroi
Copy link
Owner

ezraroi commented Oct 30, 2014

my guess is that there is not dirty checking of angular after the promise is resolved, try to update the tree data inside a $timeout or inside $apply, i think that it will solve your problem

@christophla
Copy link
Author

That’s likely. I’ve run into this before… but at the same time, I use the exact same approach to update grids and repeaters and it works just fine.

On Oct 30, 2014, at 4:46 PM, Roi Ezra notifications@github.com wrote:

my guess is that there is not dirty checking of angular after the promise is resolved, try to update the tree data inside a $timeout or inside $apply, i think that it will solve your problem


Reply to this email directly or view it on GitHub #7 (comment).

@ezraroi
Copy link
Owner

ezraroi commented Oct 30, 2014

I would also suggest that you initialize the treeData with empty array and just push all the nodes to that array once the promise is resolved, because otherwise you are changing the array reference after the tree was created.

@christophla
Copy link
Author

My same implementation works fine with https://github.com/arvindr21/jsTree-directive https://github.com/arvindr21/jsTree-directive

I ported to yours because I need the ability to set the tree instance to a scope variable….

On Oct 30, 2014, at 4:40 PM, Roi Ezra notifications@github.com wrote:

Hi,
can you write a plunker with the code? basically you don't have to force, the update should happen automatically. You can look on the demo code for example. Are you using $http to load the data async?


Reply to this email directly or view it on GitHub #7 (comment).

@ezraroi
Copy link
Owner

ezraroi commented Oct 30, 2014

Did you try to initialize the array like i suggested? If you still have the problem i would need a way to reproduce it as loading async data works fine for me on my projects.

@ezraroi ezraroi self-assigned this Oct 30, 2014
@christophla
Copy link
Author

If you were to change the scope watcher in you code to look at the array instance versus the array contents, how would you go about it?

On Oct 30, 2014, at 4:51 PM, Roi Ezra notifications@github.com wrote:

I would also suggest that you initialize the treeData with empty array and just push all the nodes to that array once the promise is resolved, because otherwise you are changing the array reference after the tree was created.


Reply to this email directly or view it on GitHub #7 (comment).

@ezraroi
Copy link
Owner

ezraroi commented Oct 30, 2014

I think that it will miss the whole point of the binding. You don't want to change the array instance on every new item or updated item in the tree. If you want to replace the whole array content you ca do this with the should-apply method. Set the method to return false before you clear the array, make all the changes in the array, update a version property in the jsTree config object, this will cause the tree to destroyed and created again with the new data

@christophla
Copy link
Author

I have a deliverable and will figure it out tomorrow. Until then, it's angular scope madness.

@ezraroi
Copy link
Owner

ezraroi commented Oct 31, 2014

Hi,
i added a section in the ReadMe that explains about how to recreate the tree.

@ezraroi
Copy link
Owner

ezraroi commented Oct 31, 2014

I also added async load and tree recreate examples in the demo page of the directive (http://ezraroi.github.io/ngJsTree/). I hope this can help you

@christophla
Copy link
Author

I applied the timeout to the callback and the tree loaded. Thanks!

P.S. Do you have any examples for asynchronously loading child nodes on expand? Should I catch the expand event and add them then?

@ezraroi
Copy link
Owner

ezraroi commented Oct 31, 2014

Hi, yes. This is right way to do this as i see it. Subscribe for the event, and load the data async and add it to the nodes array.

@ezraroi ezraroi closed this as completed Oct 31, 2014
@christophla
Copy link
Author

Thanks again!

@ezraroi
Copy link
Owner

ezraroi commented Oct 31, 2014

np

@brunolellis
Copy link

Hello @ezraroi,
It looks like the 'parent' attribute is required for this async operation.

Do you know if there is a way to configure parent as default to '#'?

Thanks!

@elahekaramzade
Copy link

hi . im using angularjs and $http service , and have this issue too . any help ?

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

4 participants