【发布时间】:2016-09-18 08:04:07
【问题描述】:
我有一个显示可选信息的表格。有时会有可选择的子行。
如果父行没有子行,我希望它们是可选的,否则只有子行应该是可选的。这是一种仅选择一种类型的表。
Right now the parent rows are selectable, but when the row with the child rows is selected, everything is selected.我正在使用嵌套的 ng-repeats,所以这使事情变得复杂。
这里是一个笨蛋。
http://plnkr.co/edit/baCIxeJB5JeVAJU8O7Hy?p=preview
选择在 plunker 中不起作用,但它在我的机器上……我正在运行 Angular 1.4.7 和 ui_bootstrap 1.1.2。但是,我认为这足以了解发生了什么。
这里是标记:
<div ng-controller="DemoCtrl">
<table class="table">
<thead>
<tr>
<th>S</th>
<th>R</th>
<th>Se</th>
<th>D</th>
<th>Ser</th>
<th>L</th>
</tr>
</thead>
<tbody ng-repeat="x in pro" ng-class="{'selected':$index == selectedRow}" ng-click="setClickedRow($index)">
<tr >
<td><b>{{x.a}}</b></td>
<td>{{x.b}}</td>
<td><u>{{x.c}}</u></td>
<td>{{x.d}}</td>
<td>{{x.e}}</td>
<td>{{x.f}}</td>
<tr ng-repeat = "details in x.jobs">
<td></td>
<td></td>
<td></td>
<td></td>
<td>{{details.name}}</td>
<td>{{details.jobs}}</td>
</tr>
</tbody>
</table>
</div>
这里是控制器
$scope.setClickedRow = function(index){
$scope.selectedRow = ($scope.selectedRow == index) ? null : index;
};
$scope.pro = [
{
a : "G",
b : "123",
c : "S1",
d : "D6",
e : "O1",
f : "B",
jobs : [
{
"name": "Wakeup",
},
{
"name": "work 9-5",
}
]
},
{
a : "R",
b : "456",
c : "S2",
d : "D5",
e : "O2",
f : "B",
jobs : [
]
},
{
a : "G",
b : "789",
c : "S3",
d : "D4",
e : "O3",
f : "P",
jobs : [
{
"name": "Sleep",
},
{
"name": "get ready for bed",
}
]
},
];
}
【问题讨论】:
标签: javascript angularjs select html-table angularjs-ng-repeat