Reputation: 83
I have a service that retrieves a JSON from an url, I use ng-repeat
to show values in a list.
My JSON
looks like this:
[
{"iconuser":"livingroom1","class":"w5","status":"0"},
{"iconuser":"meetingroom1","class":"w4","status":"1"}
]
How do I replace some values of that object.
example:
status = 0
should be status = OFF
status = 1
should be status = ON
Upvotes: 0
Views: 110
Reputation: 4401
In native angular:
$scope.item = [{"iconuser":"livingroom1","class":"w5","status":"0"},
{"iconuser":"meetingroom1","class":"w4","status":"1"}];
angular.forEach($scope.item,, function(obj) {
if(obj.status === 0)
obj.status = "OFF";
else
obj.status = "ON";
return obj;
});
Upvotes: 1
Reputation: 104775
You can use Array.map
to format your response:
var formattedData = responseData.map(function(obj) {
if (obj.status === 0) {
obj.status = "OFF";
} //etc
return obj;
});
Upvotes: 1