如何使用表行id作为angularjs函数的参数

How can i use table row id as parameter for angularjs function

本文关键字:angularjs 函数 参数 作为 id 何使用      更新时间:2023-09-26

如何获取data-id属性的值并将其作为showData()函数的参数传递?

<tr ng-repeat="schedule in schedules" ng-model="schedID" data-id="{{schedules.indexOf(schedule)}}">
  <td>MON-THU</td>
  <td>ACTIVITY CENTER</td>
  <td>National Service Training Program 2 (MERGED)</td>
  <td>0</td>
  <td>
    <input type="button" ng-click="showData()">
  </td>
</tr>

改为使用$index:

<tr ng-repeat="schedule in schedules" ng-model="schedID" data-id="{{schedules.indexOf(schedule)}}">
  <td>MON-THU</td>
  <td>ACTIVITY CENTER</td>
  <td>National Service Training Program 2 (MERGED)</td>
  <td>0</td>
  <td>
    <input type="button" ng-click="showData(schedules.indexOf(schedule))">
  </td>
</tr>