我有许多分类,每个分类又包含很多项。现在我从API返回了一个分类列表和一个项列表。
现在我希望在Angular中将它们合并成一个对象。我已经按照以下步骤进行操作:
if ($scope.categories_norm) {
$scope.delivery_items = [];
//get categories
angular.forEach(data.item_categories.normal_categories, function (v, k) {
//push categories
$scope.delivery_items.push(v);
//push items for categories
var i = 0;
if ($scope.items) {
angular.forEach($scope.items, function (val, key) {
i++;
if (val.item_category_id == v.item_category_id) {
//console.log();
$scope.delivery_items[k][i].push(val);
}
});
}
});
}
由于某些原因,我无法填充它。它返回错误:TypeError: Cannot read property 'push' of undefined。
我该如何正确操作?我想在每个类别对象内部使用一个包含所有项目的对象。