From aaed27599f3499446868c1d4057b42746a43df81 Mon Sep 17 00:00:00 2001 From: jiazhong Date: Tue, 23 Dec 2014 15:25:40 +0800 Subject: [PATCH] fix js exception caused by page not ready auto load job&cube list --- webapp/app/js/controllers/cubes.js | 3 +-- webapp/app/js/controllers/job.js | 4 ++-- webapp/app/js/directives/directives.js | 15 +++++++++------ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/webapp/app/js/controllers/cubes.js b/webapp/app/js/controllers/cubes.js index 8af23fd..62a0472 100644 --- a/webapp/app/js/controllers/cubes.js +++ b/webapp/app/js/controllers/cubes.js @@ -75,8 +75,7 @@ KylinApp }; $scope.$watch('project.selectedProject', function (newValue, oldValue) { - //exclude when refresh page oldValue=null,first time set value for project (will have page auto reload ,incase duplicate) oldvalue is null - if(newValue!=oldValue){ + if(newValue!=oldValue||newValue==null){ $scope.cubes=[]; $scope.reload(); } diff --git a/webapp/app/js/controllers/job.js b/webapp/app/js/controllers/job.js index 424f2aa..bd3e055 100644 --- a/webapp/app/js/controllers/job.js +++ b/webapp/app/js/controllers/job.js @@ -45,7 +45,7 @@ KylinApp $scope.list = function (offset, limit) { if(!$scope.project.projects.length){ - return; + return []; } offset = (!!offset) ? offset : 0; @@ -98,7 +98,7 @@ KylinApp $scope.$watch('project.selectedProject', function (newValue, oldValue) { - if(newValue!=oldValue){ + if(newValue!=oldValue||newValue==null){ $scope.jobs={}; $scope.state.projectName = newValue; $scope.reload(); diff --git a/webapp/app/js/directives/directives.js b/webapp/app/js/directives/directives.js index 264cb05..e114f20 100644 --- a/webapp/app/js/directives/directives.js +++ b/webapp/app/js/directives/directives.js @@ -47,12 +47,15 @@ KylinApp.directive('kylinPagination', function ($parse, $q) { scope.reload = function () { var length = scope.getLength(scope.data); - scope.loadFunc(0, scope.limit).then(function (dataLength) { - scope.data = $parse(attrs.data)(scope.$parent); - scope.hasMore = dataLength == scope.limit; - - return scope.data; - }); + var _resp = scope.loadFunc(0, scope.limit); + if(_resp.length){ + _resp.then(function (dataLength) { + scope.data = $parse(attrs.data)(scope.$parent); + scope.hasMore = dataLength == scope.limit; + + return scope.data; + }); + } } if (scope.autoLoad) {