将变量添加到现有 json 对象
Add variable to an existing json object
request = myService.getCases();
request.then(
function(payload) {
$scope.cases = payload.data;
var time = Math.floor((Date.now() - Date.parse($scope.cases[i].date_case_modified))/(60000*60*24));
$scope.cases.duration.push(time);
}
});
在控制器内部,我试图将 cases.duration 添加到案例对象上,但它不会将其添加到返回的对象上。有什么想法吗?
我想你只需要引入一个 forEach
如下所示:
request = myService.getCases();
request.then(
function(payload) {
$scope.cases = payload.data;
angular.forEach($scope.cases, function (el) {
var time = Math.floor((Date.now() - Date.parse(el.date_case_modified))/(60000*60*24));
el.duration = time;
});
}
});
希望对您有所帮助
request = myService.getCases();
request.then(
function(payload) {
$scope.cases = payload.data;
var time = Math.floor((Date.now() - Date.parse($scope.cases[i].date_case_modified))/(60000*60*24));
$scope.cases.duration.push(time);
}
});
在控制器内部,我试图将 cases.duration 添加到案例对象上,但它不会将其添加到返回的对象上。有什么想法吗?
我想你只需要引入一个 forEach
如下所示:
request = myService.getCases();
request.then(
function(payload) {
$scope.cases = payload.data;
angular.forEach($scope.cases, function (el) {
var time = Math.floor((Date.now() - Date.parse(el.date_case_modified))/(60000*60*24));
el.duration = time;
});
}
});
希望对您有所帮助