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

Crashes on Asyncronous load via angular query #99

Open
jmoseman01 opened this issue Nov 10, 2016 · 3 comments
Open

Crashes on Asyncronous load via angular query #99

jmoseman01 opened this issue Nov 10, 2016 · 3 comments

Comments

@jmoseman01
Copy link

jmoseman01 commented Nov 10, 2016

No description provided.

@jmoseman01
Copy link
Author

<div js-tree="vm.treeConfig" ng-model="vm.nodes" tree="treeInstance" ></div> <!-- should-apply="ignoreModelChanges()" tree="treeInstance" tree-events="ready:readyCB;create_node:createNodeCB"></div> -->

@jmoseman01
Copy link
Author

jmoseman01 commented Nov 10, 2016

function HomeController ($scope, Principal, LoginService, $state, Node,AlertService) {
        var vm = this;

        //jstree
        vm.ignoreChanges = false;
        vm.treeConfig = {
                core : {
                    multiple : false,
                    animation: true,
                    error : function(error) {
                        $log.error('treeCtrl: error from js tree - ' + angular.toJson(error));
                    },
                    check_callback : true,
                    worker : true
                },
                types : {
                    default : {
                        icon : 'glyphicon glyphicon-flash'
                    },
                    star : {
                        icon : 'glyphicon glyphicon-star'
                    },
                    cloud : {
                        icon : 'glyphicon glyphicon-cloud'
                    }
                },
                version : 1,
                plugins : ['types','checkbox']
            };
        //jstree

        vm.nodes=[];

        // load all
         loadAll();

        function loadAll () {
            Node.query({}, onSuccess, onError);
            function onSuccess(data, headers) {
                for(var i=0;i<data.length;i++)
                {
                    var node={};
                    node.id=data[i].idstr;
                    node.text=data[i].text;
                    node.parent=data[i].parent;
                    node.state={opened:true};
//                    node.children=data[i].children;
                    vm.nodes.push(node);
                }
            }
            function onError(error) {
                AlertService.error(error.data.message);
            }
        }
        //load all

@periface
Copy link

periface commented Dec 6, 2016

Hi jmoseman01, i had the same problem i fixed it by setting the should-apply property of the directive to false, and then in my controller i created a function to reload the tree when the model is updated

function reloadTree(){
     vm.treeConfig.version ++;
}
_orgUnits.getOrganizationUnitsConfigModel().then(function (response) {
      var treeModel = response.data;
      for (var i = 0; i < treeModel.organizationUnits.length; i++) {
                buildTreeData(treeModel.organizationUnits[i]);
      }
      reloadTree();
});

The problem is that you must call the reloadTree method every time you update the tree model.
Also i readed something about disabling the worker option in the core configuration object here #54

I hope it helps.

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

2 participants