获取<td>onclick到另一个<td>与Angular位于同一行

Get value of a <td> onclick to an other <td> of the same row with Angular

本文关键字:gt td lt 于同一 Angular onclick 获取 另一个      更新时间:2023-09-26

如果我单击同一行的其他<td>,我想获得数据单元格<td>的值。

 <tr ng-repeat="x in names">
   <td>{{ x.Name }}</td>
   <td>{{ x.Country | uppercase }}</td>
 </tr>

解决问题的一种方法是http://jsfiddle.net/L60L3gv9/

$scope.getValueOfTD = function(x){
    alert(x.Name);    
}

但就我而言,我的数据单元之间没有任何联系。有没有一种方法可以用这样的标准函数来获得这个值?

$scope.getValueOfTD = function(){
}

任何解决方案都可以

您可以在tr:上使用ng-click

JSFiddle

HTML:

<table>
  <th>Column1</th>
  <th>Column2</th>
  <tr ng-repeat="x in names" ng-click="getValueOfTD(x)">
    <td>{{ x.Name }}</td>
    <td>{{ x.Country | uppercase }}</td>
  </tr>
</table>

JS:

$scope.getValueOfTD = function (user) {
    console.log(user.Name);
}