使用ng-repeat迭代hasmap。数组为值的Hashmap

时间:2015-07-26 19:02:03

标签: angularjs angularjs-directive angularjs-scope angularjs-ng-repeat

如何使用ng-repeat在UI上使用angularJS从服务器迭代JSON响应?

$scope.data = {
  "Home Needs": [{
    "id": 11,
    "itemName": "PARLE G 500 Grams",
    "itemPrice": 50,
    "minSellPrice": 45,
    "discount": 0,
    "store": "Home Needs"
  }],
  "SRI SAI Store": [{
    "id": 1,
    "itemName": "PARLE G 500 Grams",
    "itemPrice": 50,
    "minSellPrice": 45,
    "discount": 0,
    "store": "SRI SAI Store"
  }],
  "Ashirwad": [{
    "id": 10,
    "itemName": "PARLE G 500 Grams",
    "itemPrice": 50,
    "minSellPrice": 46,
    "discount": 0,
    "store": "Ashirwad"
  }]
}

任何人都可以帮我找一个jsfiddle或指针吗?

感谢

1 个答案:

答案 0 :(得分:4)

请检查https://stackoverflow.com/a/17037364/1979882

<div ng-app>
     <div ng-controller="ClickToEditCtrl">
          <p>Your Data:</p>
         <ul ng-repeat="(key, value) in data">
          name: {{key}}
        <li ng-repeat="v in value">
            {{v.id}},
            {{v.itemName}},
            {{v.itemPrice}},
            {{v.minSellPrice}},
            {{v.discount}},
            {{v.store}}
        </li>
    </ul>
    </div>
</div>

您可以根据需要进行修改。我希望这可能有所帮助。