Angular 遍歷循環數組
var app = angular.module(‘Mywind‘,[‘ui.router‘])
app.controller(‘Myautumn‘,function($scope,$http,$filter){
var objs =[{a:1},{a:2}];
angular.forEach(objs, function(data,index,array){
//data等價於array[index]
console.log(data.a+‘=‘+array[index].a);
// console.log(data.a);
//轉化為小寫
console.log(angular.lowercase("A"))
//轉化為大寫
console.log(angular.uppercase("b"))
});
//$http
$scope.SWLogin = function() {
$http({
method: ‘POST‘,
url: url + ‘‘,
params: {}
}).then(function successCallback(response) {
$scope.val = response.data
//map 循環遍歷
var role = {
"1":‘文字a‘,
"6":‘文字b‘,
"9":‘文字c‘,
"7":‘文字d‘,
"3":‘文字e‘,
"5":‘文字f‘
}
//循環遍歷改變值
$scope.val = $scope.val.map(item => {
var obj = {};
//取值x.realShow
obj.realShow = role[item.prizeid] ? role[item.prizeid] : ‘‘;
return Object.assign({}, item, obj);
})
}, function errorCallback(response) {
$scope.message = message;
console.log("error:" + response + "");
});
}
});
Angular 遍歷循環數組