【问题标题】:How to loop over array values using AngularJS?如何使用AngularJS循环数组值?
【发布时间】:2017-03-07 12:19:23
【问题描述】:

我想用ng-repeat显示数组值,我会用itemid和photoidlist调用getimage函数来获取图片url。

我的json是:

$scope.productslist = {
  "json": {
    "response": {
      "servicetype": "10",
      "functiontype": "104",
      "statuscode": "0",
      "statusmessage": "Success",
      "data": [
        {
          "itemid": 247,
          "isproduct": true,
          "disable": false,
          "itemcost": 150,
          "itemdescription": "prdct",
          "itemname": "pro1",
          "itemno": "#1Pro",
          "itemcategoryid": 158,
          "itemcategory": "General",
          "addedby": "buzi by pree"
        },
        {
          "itemid": 257,
          "isproduct": true,
          "disable": false,
          "itemcost": 150,
          "itemdescription": "products",
          "itemname": "pro 2",
          "itemno": "pro 2",
          "itemcategoryid": 158,
          "itemcategory": "General",
          "photoidlist": [
            138
          ],
          "addedby": "buzi by pree"
        },
        {
          "itemid": 259,
          "isproduct": true,
          "disable": false,
          "itemcost": 150,
          "itemdescription": "descc",
          "itemname": "pro 1",
          "itemno": "pro 3",
          "itemcategoryid": 158,
          "itemcategory": "General",
          "photoidlist": [
            139, 140
          ],
          "addedby": "buzi by pree"
        },
        {
          "itemid": 262,
          "isproduct": true,
          "disable": false,
          "itemcost": 599,
          "itemdescription": "fgg",
          "itemname": "ff",
          "itemno": "r",
          "itemcategoryid": 158,
          "itemcategory": "General",
          "addedby": "buzi by pree"
        },
        {
          "itemid": 263,
          "isproduct": true,
          "disable": false,
          "itemcost": 56,
          "itemdescription": "ffr",
          "itemname": "rf",
          "itemno": "fe",
          "itemcategoryid": 158,
          "itemcategory": "General",
          "photoidlist": [
            140, 143, 141
          ],
          "addedby": "buzi by pree"
        }
      ]
    }
  }
};

现在我需要使用 ng-repeat 遍历数组并显示所有具有特定值的值。

我创建了一个Fiddle

【问题讨论】:

    标签: javascript angularjs arrays json angularjs-ng-repeat


    【解决方案1】:

    你的逻辑很好,但你试图迭代一个对象,而不是一个数组。我觉得应该是这样的:

    <tr ng-repeat="item in productslist.json.response.data">
         ...
    </tr>
    

    Forked your Fiddle here.

    【讨论】:

      猜你喜欢
      • 2014-11-11
      • 1970-01-01
      • 2021-12-25
      • 2021-04-02
      • 2021-10-17
      • 2017-01-03
      • 2017-07-22
      • 1970-01-01
      • 2019-06-02
      相关资源
      最近更新 更多