本文介绍了在 angular JS 中创建矩阵表的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的 JSON 对象(部分),我想最好使用 ng-repeat 将其显示为矩阵表:

[{"产品": "牛奶","资源": "a",检查":真},{"产品": "面包","资源": "a",检查":假},{"产品": "黄油","资源": "a",检查":真}]

我尝试过 http://plnkr.co/edit/iW1dZV?p=info 但我不想使用 coffeescript.

解决方案

@forgottofly 这里是一个更好的 json 示例,可以满足您的需求:

[{"资源": "a",产品: [{"产品": "牛奶",检查":真}, {"产品": "面包",检查":假}, {"产品": "黄油",检查":真}]}, {"资源": "b",产品: [{"产品": "牛奶",检查":假}, {"产品": "面包",检查":真}, {"产品": "黄油",检查":真}]}, {"资源": "c",产品: [{"产品": "牛奶",检查":假}, {"产品": "面包",检查":真}, {"产品": "黄油",检查":真}]}]

Below is my JSON object(partial) which I would like to show as a matrix table preferably using ng-repeat:

[
    {
        "product": "milk",
        "resource": "a",
        "checked": true
    },
    {
        "product": "bread",
        "resource": "a",
        "checked": false
    },
    {
        "product": "butter",
        "resource": "a",
        "checked": true
    }
]

I have tried http://plnkr.co/edit/iW1dZV?p=info but I don't want to use coffeescript.

解决方案

@forgottofly here is an example of better json for what you need:

[{
  "resource": "a",
  products: [{
    "product": "milk",
    "checked": true
  }, {
    "product": "bread",
    "checked": false
  }, {
    "product": "butter",
    "checked": true
  }]
}, {
  "resource": "b",
  products: [{
    "product": "milk",
    "checked": false
  }, {
    "product": "bread",
    "checked": true
  }, {
    "product": "butter",
    "checked": true
  }]
}, {
  "resource": "c",
  products: [{
    "product": "milk",
    "checked": false
  }, {
    "product": "bread",
    "checked": true
  }, {
    "product": "butter",
    "checked": true
  }]
}]

这篇关于在 angular JS 中创建矩阵表的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 09:59