访问内部重复对象以适合表格

时间:2016-03-04 06:25:06

标签: javascript html angularjs html5 authentication

我从JSON格式的后端调用中获取此数据。我在创建数据结构以处理首页中的数据时遇到了很多问题,从中获取响应并将其发送回后端。

[


{
    "name": "dataAccess",
    "description": null,
    "type": null,
    "permission": [
      {
        "name": "delete",
        "description": null,
        "enabled": false
      },
      {
        "name": "edit",
        "description": null,
        "enabled": false
      },
      {
        "name": "export",
        "description": null,
        "enabled": false
      },
      {
        "name": "write",
        "description": null,
        "enabled": false
      },
      {
        "name": "read",
        "description": null,
        "enabled": false
      }
    ]
  },
  {
    "name": "entity",
    "description": null,
    "type": null,
    "permission": [
      {
        "name": "export",
        "description": null,
        "enabled": false
      },
      {
        "name": "edit",
        "description": null,
        "enabled": false
      },
      {
        "name": "write",
        "description": null,
        "enabled": false
      },
      {
        "name": "read",
        "description": null,
        "enabled": false
      },
      {
        "name": "delete",
        "description": null,
        "enabled": false
      }
    ]

  }
]

有对象名称,权限名称和对象相关权限。外部循环名称指定对象名称(例如:Dataaccess),内部循环(权限)指定此Dataaccess对象具有的权限(即删除,读取等)。 这些权限不是静态的,可以随时添加到SQL中,因此我必须创建一个数组。

以下是我在HTML页面中想要的内容。

表格的行将是权限名称,列将这些权限映射到对象。

 ModuleName      Read        Edit      Delete       Export      write
 dataAccess    CheckBox  Checkbox    ChecckBox    CheckBox    CheckBox
 Entity        CheckBox  Checkbox    ChecckBox    CheckBox    CheckBox

这些复选框的值是这些权限所具有的值,即如果为false,则该特定对象权限的复选框将被取消,反之亦然。

用户可以编辑此页面取消选中复选框,我必须返回具有更新值的相同JSON数组。

我尝试在html中的ng-repeat中使用ng-repeat,但这导致两个头,因为我现在有两行。它们会随着行增加而增加,这是我不想要的。

我尝试过创建自定义过滤器,指令,但我无法正确放置权限。它们总是不匹配。如果我能够做到这一点,我将无法获取更新的值。

1 个答案:

答案 0 :(得分:0)

最后我发现了自己!!!

这是我在Controller中所做的,我按顺序重新排列了数据序列。

<table class="table table-bordered table-bordered">
        <thead >
        <tr>
            <th>Module</th>
            <th ng-repeat="maindata in PermissionNames">{{maindata.name}}</th>
        </tr>
        </thead>
        <tbody>
        <tr ng-repeat="Object in ObjectPermissions ">
            <td >{{Object.name}}</td>
            <td ng-repeat="permissionValue in Object.permission" >

                    <input type="checkbox" ng-model="permissionValue.enabled"  
                            ng-checked="permissionValue.enabled"
                            ng-click="checkValue($parent.$index,$index,permissionValue.enabled)">

            </td>

        </tr>
        </tbody>
    </table>

因此,它们将始终排序,然后我在HTML \

中使用它
-eq

如何帮助任何面临类似问题的人