javascript - 如何使用 AngularJS 循环数组值?

标签 javascript angularjs arrays json angularjs-ng-repeat

我想使用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

最佳答案

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

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

Forked your Fiddle here.

关于javascript - 如何使用 AngularJS 循环数组值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42648138/

相关文章:

javascript - 将 Promise 挂起作为变量中的值

javascript - 显示和隐藏带链接的 div

angularjs - 如何在 angular1.5 comps 中修复页脚

java将文件的输出存储到数组中

javascript - Vue.js 将一个元素从另一个数组添加到一个数组

javascript - JavaScript 中的 Number() 和 ToNumber() 有什么区别?

javascript - insertBefore 正在复制内容

javascript - webgl 丢失对 javascript 中对象的引用

javascript - 剑道卡住(锁定)网格高度

javascript - UI-Bootstrap 示例不起作用