我正在嘗試爲我的網站創建一個商店頁面。我想顯示以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