我有一个包含多行的表格,每一行都有一个<td>
叫ID
。
<table>
<thead>
<tr>
<th>
ID
</th>
<th>
XYZ
</th>
<th>
XYZ
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<a href="">10</a>
</td>
<td>
XYZ
</td>
<td>
XYZ
</td>
</tr>
<tr colspan="3" class="more-info">
<!-- I want to show this row if the $stateparams has an id === 10; -->
</tr>
<tr>
<td>
<a href="">120</a>
</td>
<td>
XYZ
</td>
<td>
XYZ
</td>
</tr>
<tr colspan="3" class="more-info">
<!-- I want to show this row if the $stateparams has an id === 120; -->
</tr>
<tr>
<td>
<a href="">420</a>
</td>
<td>
XYZ
</td>
<td>
XYZ
</td>
</tr>
<tr colspan="3" class="more-info">
<!-- I want to show this row if the $stateparams has an id === 420; -->
</tr>
</tbody>
</table
&#13;
当您点击ID时,会向服务器发送请求以获取ID
的数据。数据将显示在行ID
行下方的表格行中。点击还会更新url
,例如从localhost:3000/app
更新为localhost:3000/app/420
。
如何仅显示与table row
匹配的行下方的stateparams.id
?如果您刷新页面(localhost:3000/app/420
),它仍应显示。
提前致谢!
答案 0 :(得分:1)
你可以这样做:
在Html中:
<tr colspan="3" class="more-info" ng-if="CurrentID=='120'">
<!-- I want to show this row if the $stateparams has an id === 120; -->
</tr>
在JS中
app.controller("myCtrl", function($scope,$stateParams) {
$scope.CurrentID = 0;
if($stateParams.id != undefined){
$scope.CurrentID = $stateParams.id;
}
});