【发布时间】:2016-11-09 23:21:25
【问题描述】:
我有一个填满数据的表格; 我有一个删除一行的按钮, 我有输入字段,显示表格中选定行的数据。
首先我必须选择该行...然后输入字段r 填充来自同一行的数据...一旦我完成它,我可以按删除...该行是已删除...现在选择了该已删除行下方的行...(我可以将其更改为不)...但是已删除行中的旧值仍在输入字段中...
现在我必须做点什么...2 个选项:
将选中的行设置为空,并清除所有输入字段...(我不知道该怎么做...)
使用新选定的行并将其数据填充到输入字段中...witch 在我看来是更好的方法...
所以请帮帮我,这里是代码:
在我的 html 文件中,我有这个:
<p>ID</p>
<input ng-model="student.id">
<p>Name</p>
<input ng-model="student.firstname">
<p>Last Name</p>
<input ng-model="student.lastname">
<button ng-click="deleteStudent(student)">Delete Student</button>
<table name="tableStud" arrow-selector>
<tbody>
<tr>
<td>ID</td>
<td>First Name</td>
<td>Last Name</td>
<td>From</td>
</tr>
<tr ng-repeat="student in result"
ng-class="{'selected':$index == selectedRow}"
ng-click="setSelected(student,$index)">
<td>{{ student.id }}</td>
<td>{{ student.firstname }}</td>
<td>{{ student.lastname }}</td>
<td>{{ student.mestorodjenja.ime }}</td>
</tr>
</tbody>
</table>
我有一个控制器....用这个:
$scope.deleteStudent = function(student) {
$http.post('http://localhost:8080/CreditCardWEB/rest/cc/delete',
student).success(function(data) {
$scope.result.splice($scope.selectedRow, 1);
});
};
$scope.selectedRow = null;
$scope.setSelected = function(student, index) {
$scope.student = student;
$scope.selectedRow = index;
};
【问题讨论】:
标签: javascript angularjs html-table