我的基础是这个例子: http://code.ciphertrick.com/2014/12/06/highlight-a-selected-row-in-ng-repeat-using-ng-class/ 演示: http://code.ciphertrick.com/demo/ngClass/
示例工作正常,但我需要添加一个按钮元素,当我点击按钮时,我想在警告中显示名称列的值,例如&#34; Noodles&#34; < / p>
这是我的代码html:
<table class="table table-hover">
<thead>
<tr>
<th>Branch</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="organizational in organizationals" ng-class="{'selected':$index == selectedRow}" ng-click="setClickedRow($index)">
<td>{{organizational.branch}}</td>
<td>{{organizational.name}}</td>
</tr>
</tbody>
</table>
<button type="button" class="btn btn-default" ng-click="createSelectRowClick();">Select</button>
这是我的js代码:
$scope.managers = [
{name: 'Ana Faedo Iglesias'},
{name: 'Cristina Menendez'},
{name: 'Daniel Piriz'}
];
$scope.selectedRow = null;
$scope.setClickedRow = function(index){
$scope.selectedRow = index;
}
$scope.createSelectRowClick = function(){
if ($scope.selectedRow==null)
{
alert("Any rows selected");
}
else
{
//alert("valuetd" + value td column name, about click row);
}
}
注意:该表位于模态窗口中,如果我在表格行中单击,我恢复列的值,我关闭窗口模态,之后,我可以将列值放在任何地方。
怎么办?感谢,
答案 0 :(得分:1)
希望这能解决您的问题。
$scope.createSelectRowClick = function(){
if ($scope.selectedRow==null)
{
alert("Any rows selected");
}
else
{
alert("valuetd " + $scope.organizationals[$scope.selectedRow].name);
}
}