2015-02-08 74 views
1

如何獲取data-id屬性的值並將其作爲showData()函數的參數傳遞?如何使用錶行ID作爲angularjs函數的參數

<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>

+0

可以顯示控制器代碼,請 – 2015-02-08 09:42:55

回答

0

使用$指數來代替:

<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> 
+0

我想你的解決方案,但$指數變化的值時篩選表的內容。使用indexOf的值保持不變,但我的問題是如何將它傳遞給showData()函數作爲參數。 – renepar 2015-02-08 09:58:42

+0

數據更改時,索引將始終更改。爲什麼不只是傳遞對象本身? – 2015-02-08 10:00:43

+0

您是否使用該對象?爲什麼我的回答突然被接受了? – 2015-02-08 10:12:16

相關問題