我有一个从网址检索JSON的服务,我使用JSON
在列表中显示值。
我的[
{"iconuser":"livingroom1","class":"w5","status":"0"},
{"iconuser":"meetingroom1","class":"w4","status":"1"}
]
看起来像这样:
status = 0
如何替换该对象的某些值。
示例:
status = OFF
应为status = 1
status = ON
应为(output * sd) + mean
答案 0 :(得分:1)
您可以使用Array.map
格式化您的回复:
var formattedData = responseData.map(function(obj) {
if (obj.status === 0) {
obj.status = "OFF";
} //etc
return obj;
});
答案 1 :(得分:1)
原生角度:
$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;
});