按月存檔:7 月 2017

動態排序後執行function

var queue = [];

$scope.queue = [
{
‘key’: ‘KEY’,
‘value’: get from DB,
‘func’: runSomething
},
{
‘key’: ‘KEY_1’,
‘value’: get from DB,
‘func’: runSomething_1
}
];

// 排序
$scope.queue = $filter(‘orderBy’)($scope.queue, ‘value’, true);

queue = angular.copy($scope.queue);

 

function execQueue() {
if (queue.length === 0 ) {
$scope.finish();
} else {
var funcObj = queue.shift();
funcObj.func();
}
}

function doConfirm(type, msg) {
switch (type) {
case ‘2’:
confirm(msg[‘2’])
.then(function () {
execQueue();
});
break;
case ‘3’:
alert(msg[‘3’]);
break;
default:
execQueue();
break;
}
}

 

function runSomething() {
if (condition1) {
execQueue();
} else {
if (condition2) {
doConfirm();
} else {
execQueue();
}
}

}

function runSomething_1() {
if (condition1) {
execQueue();
} else {
if (condition2) {
doConfirm();
} else {
execQueue();
}
}
}