我正在尝试为我的网站创建一个商店页面。我想显示以ng重复以下JSON文件:如何在ng-repeat中正确显示此json文件?
{
"cupcakes": {
"Vanilla": [
{"price":"9.99", "stock":"20", "amount":"8",
"ingredients":"flour, sugar, vanilla extract",
"popular":true}
],
"Maple": [
{"price":"9.99", "stock":"15", "amount":"8",
"ingredients":"flour, sugar, maple syrup",
"popular":true}
]
},
"cookies": {
"Vanilla": [
{"price":"7.99", "stock":"50", "amount":"12", "ingredients":"flour, sugar, vanilla extract"}
],
"Maple": [
{"price":"7.99", "stock":"50", "amount":"12", "ingredients":"flour, sugar, maple syrup"}
]
}
}
我想显示的类型的项目(蛋糕或饼干),那么每个项目(香草或枫木)的类型,那么独特的属性并能够过滤和搜索它们。我想我可能不得不重构我的json文件,但我不确定。我应该使用forEach在控制器中提前清理项目吗?这里是我的控制器:
angular.module('root', [])
.controller("index", ['$scope', '$http', function ($scope, $http) {
$scope.name = null;
$scope.email = null;
$scope.comments = null;
$scope.reason = null;
$scope.employees = [];
$scope.items = [];
$http.get('http://localhost:8000/employees.json').then(function(result) {
$scope.employees = result.data.records;
});
$http.get('http://localhost:8000/inventory.json').then(function(result) {
$scope.items = result.data;
});
$scope.isEnabled = function() {
if ($scope.name && $scope.email && $scope.comments) {
return false;
}
else {
return true;
}
}
}])
第二个想法是,如果我想向json文件添加更多数据,这不起作用。我认为这与ng-repeat标签有关。有什么建议么? – doct03
没关系我通过删除第4个不重复来解决问题。 – doct03