我在html中有很多行的表格。
<table id="selectTerminals" size="35">
<thead>
<tr>
<th>ID</th>
<th>name</th>
<th>Full Name</th>
<th>Configure</th>
</tr>
</thead>
<tbody>
<tr dir-paginate="item in serverData1 | filter:filterData | itemsPerPage: serverData1.length">
<td>{{item.id}}</td>
<td>{{item.abvrName}}</td>
<td>{{item.name}}</td>
<td><p><input class="deleteFromList" name="delete" value="Delete " type="submit" ng-click="deleteFromList()"/></p></td>
</tr>
</tbody>
</table>
并点击删除按钮我想在deleteFromList()函数中选择项目ID,我需要帮助,因为我不知道我该怎么做。
答案 0 :(得分:0)
<table id="selectTerminals" size="35">
<thead>
<tr>
<th>ID</th>
<th>name</th>
<th>Full Name</th>
<th>Configure</th>
</tr>
</thead>
<tbody>
<tr dir-paginate="item in serverData1 | filter:filterData | itemsPerPage: serverData1.length">
<td>{{item.id}}</td>
<td>{{item.abvrName}}</td>
<td>{{item.name}}</td>>
<!-- Pass `this` to the deleteFromList -->
<td><p><input class="deleteFromList" name="delete" value="Delete " type="submit" ng-click="deleteFromList(this)"/></p></td>
</tr>
</tbody>
</table>
<script type="text/javascript">
/* Assuming your function like this. */
function deleteFromList(ele)
{
/* You could get the specified id by this. */
var id = ele.parentNode.parentNode.parentNode.firstElementChild.innerHTML;
// other logic.
}
</script>
你可以这样做。
答案 1 :(得分:0)
我认为你的html模板看起来像这样:
$scope.deleteFromList = function(item) {
var index = $scope.serverData1.indexOf(item);
$scope.serverData1 = $scope.serverData1.slice(index, 1);
}
然后在您的控制器中执行以下操作:
{{1}}