angularjs - ng-repeat: access key and value from JSON array object

后端 未结 4 643
粉色の甜心
粉色の甜心 2020-12-04 13:14

I have JSON Array object as shown below.

$scope.items = 
    [
    {Name: \"Soap\",  Price: \"25\",  Quantity: \"10\"},
    {Name: \"Bag\",   Price: \"100\",         


        
4条回答
  •  无人及你
    2020-12-04 14:07

    I have just started checking out Angular(so im quite sure there are other ways to get it done which are more optimum), and i came across this question while searching for examples of ng-repeat.

    The requirement by the poser(with the update):

    "...but my real requirement is display the items as shown below.."

    looked real-world enough (and simple), so i thought ill give it a spin and attempt to get the exact desired structure.

    angular.module('appTest', [])
      .controller("repeatCtrl", function($scope) {
        $scope.items = [{
          Name: "Soap",
          Price: "25",
          Quantity: "10"
        }, {
          Name: "Bag",
          Price: "100",
          Quantity: "15"
        }, {
          Name: "Pen",
          Price: "15",
          Quantity: "13"
        }];
      })
    
    
    
      
    {{key}}
    {{val}}

    The limitTo:(n) filter is the key. Im still not sure if having multiple ng-repeat is an optimum way to go about it, but can't think of another alternative currently.

提交回复
热议问题