Closed phuwin1995 closed 8 years ago
I have this jsTree:
<div js-tree="treeConfig" ng-model="googleDriveFiles" should-apply="ignoreModelChanges()" tree-events="ready:readyCB;changed:onTreeItemChanged" tree="treeInstance"></div>
$scope.googleDriveFiles is defined like this $scope.googleDriveFiles = []; My treeConfig:
$scope.googleDriveFiles
$scope.googleDriveFiles = [];
treeConfig
$scope.treeConfig = { core : { multiple : false, animation: true, error : function(error) { console.log(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','folder'] };
My function to push data into the array:
function fetchGoogleDriveFiles(data){ console.log("Files:"); console.log(data); for (var i = 0; i < data.length; i++) { var file = data[i]; var parent = file.parents[0]; if (parent != $scope.GDriveFolderId) parent = '#'; if (file.mimeType != "application/vnd.google-apps.folder"){ var fileData = { "id":file.id, "parent":parent, "text":file.name, "data":{url:handleLink(file)}, "state":{"opened":true} } $scope.googleDriveFiles.push(fileData); } } console.log($scope.googleDriveFiles); //$scope.treeConfig.version++; //to recreate. } function handleLink(file){ if ("webContentLink" in file){ return file.webContentLink; } else return file.webViewLink; }
I tried to recreate the tree after all the pushing (increase the version attribute in treeConfig), but it also doesn't work. May someone help?
version
After digging up the closed issues, $scope.$apply() helps.
$scope.$apply()
I have this jsTree:
$scope.googleDriveFiles
is defined like this$scope.googleDriveFiles = [];
MytreeConfig
:My function to push data into the array:
I tried to recreate the tree after all the pushing (increase the
version
attribute intreeConfig
), but it also doesn't work. May someone help?