【发布时间】:2016-12-06 15:41:21
【问题描述】:
我需要将一个 JSON 对象推送到 AngularJS,并且需要先检查其中一个对象的值是否存在。我需要覆盖数据。
$scope.setData = function(survey, choice) {
keepAllData.push({
'surveyId': survey.id,
'choiceId': choice.id
});
console.log(keepAllData);
toArray(keepAllData);
alert(JSON.stringify(toArray(keepAllData)));
$scope.keepAllDatas.push({
'surveyId': survey.id,
'choiceId': choice.id
});
var items = ($filter('filter')(keepAllDatas, {
surveyId: survey.id
}));
}
function toArray(obj) {
var result = [];
for (var prop in obj) {
var value = obj[prop];
console.log(prop);
if (typeof value === 'object') {
result.push(toArray(value));
console.log(result);
} else {
result.push(value);
console.log(result);
}
}
return result;
}
如果keepalldata中存在调查id,我需要用choiceid更改最近的值。可以用AngularJS吗?
【问题讨论】:
标签: angularjs