我正在尝试修改ng-table
以创建可扩展的节点/树视图,
JSON 结构是根据 ID 指定的。
[
{
"BodyId": 1,
"TrId": null,
"TdId": null,
"Title": "BodyId1",
"Status": "Ok"
}, {
"BodyId": 2,
"TrId": null,
"TdId": null,
"Title": "BodyId2",
"Status": "Ok"
}, {
"BodyId": 3,
"TrId": null,
"TdId": null,
"Title": "BodyId3",
"Status": "Ok"
}, {
"BodyId": 1,
"TrId": 1,
"TdId": null,
"Title": "TrId1",
"Status": "Ok"
}, {
"BodyId": 1,
"TrId": 2,
"TdId": null,
"Title": "TrId2",
"Status": "Ok"
}, {
"BodyId": 2,
"TrId": 1,
"TdId": null,
"Title": "TrId1",
"Status": "Ok"
}, {
"BodyId": 2,
"TrId": 2,
"TdId": null,
"Title": "TrId2",
"Status": "Ok"
}, {
"BodyId": 3,
"TrId": 1,
"TdId": null,
"Title": "TrId1",
"Status": "Ok"
}, {
"BodyId": 3,
"TrId": 2,
"TdId": null,
"Title": "TrId2",
"Status": "Ok"
}, {
"BodyId": 1,
"TrId": 1,
"TdId": 1,
"Title": "TdId1",
"Status": "Ok"
}, {
"BodyId": 1,
"TrId": 1,
"TdId": 2,
"Title": "TdId2",
"Status": "Ok"
}, {
"BodyId": 1,
"TrId": 2,
"TdId": "1",
"Title": "TdId1",
"Status": "Ok"
}, {
"BodyId": 2,
"TrId": 1,
"TdId": 1,
"Title": "TdId1",
"Status": "Ok"
}, {
"BodyId": 2,
"TrId": 1,
"TdId": 2,
"Title": "TdId2",
"Status": "Ok"
}, {
"BodyId": 2,
"TrId": 2,
"TdId": 1,
"Title": "TdId1",
"Status": "Ok"
}, {
"BodyId": 3,
"TrId": 3,
"TdId": 1,
"Title": "TdId1",
"Status": "Ok"
}]
我设法通过以下方式显示父节点:
<tbody>
<tr ng-repeat="node in $data" ng-show="node.TrId == null && node.TdId == null">
<td ng-repeat="column in columns" ng-show="column.visible " sortable="column.field">
<span ng-show="column.field == 'Title'"><i class="glyphicon" ng-class="{'glyphicon-minus' : node.expanded, 'glyphicon-plus' : !node.expanded}"></i></span>
{{node[column.field]}}
</td>
</tr>
</tbody>
在这里我被卡住了,因为我不知道如何在每个父节点下方附加相应的子节点并在单击后使所有节点都可展开。
解析此 JSON 结构并将其更改为 JSON 将是一个很好的解决方案,这会使这个问题更容易解决吗?
[{
BodyId: 1,
TrID: [{
Id: 1,
TdId: [{
Id: 1,
Name: "Td1"
},
{
Id: 2,
Name: "Td2"
}]
}]
}]