【发布时间】:2016-06-13 08:31:13
【问题描述】:
我在 angularjs 表中添加了每一行的复选框,并在表外添加了一个通用的删除按钮,这样就可以一次选择和删除多行。选择行并单击删除时,将删除该特定行。这很好,直到这里它也在下面的 plunker 中工作。 Now what I need is when a particular row is selected, its rowid has to be sent as a parameter to another URL.当这个带有 ids 的 URL(由选定的 rowIds 形成的 URL)被调用时,会自动从第一个 URL 数据中删除行,现在必须从第一个 URL 更新表。 null 将从第二个 url 以 ids 作为参数返回,同时将从第一个 URL 的 JSON 数据中删除行。
这是demo:http://plnkr.co/edit/UzKdIGSubEfHoF7FHoCd?p=preview
下面是表格的代码:
<div ng-controller="SampleController">
<form class="form-horizontal">
<a class="btn btn-info" ng-click="subt_click()">Submit</a>
</form>
<div class="table-responsive" ng-show="tableData.length > 0">
<table class="table table-striped table-bordered table-hover dataTables-example">
<thead>
<tr>
<th><input name="all" type="checkbox" ng-click="selectAllFriends()" /></th>
<th>ID</th>
<th>Body</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="x in tableData">
<td><input name="all" type="checkbox" ng-model="x.checked" /></td>
<td>{{x.id}}</td>
<td>{{x.body}}</td>
</tr>
</tbody>
</table>
</div>
<input ng-hide="!tableData.length" type="button" class="btn btn-danger pull-left" ng-click="remove()" value="Remove">
app.js:
$scope.remove = function () {
var newDataList = [];
$scope.selectedAll = false;
angular.forEach($scope.tableData, function (checked) {
if (!checked.checked) {
newDataList.push(checked);
}
});
$scope.tableData = newDataList;
};
$scope.isAll = false;
$scope.selectAllFriends = function () {
if ($scope.isAll === false) {
angular.forEach($scope.tableData, function (x) {
x.checked = true;
});
$scope.isAll = true;
} else {
angular.forEach($scope.tableData, function (x) {
x.checked = false;
});
$scope.isAll = false;
}
};
简而言之,我需要的是:
- 我从第一个 url 获取表数据。 (请检查 plunk,我使用的 url 是 jsonplaceholder.typicode.com/posts)
- 当从表中的一行中选中一个复选框并单击删除按钮时,该 rowid 必须发送到第二个 URL(需要调用另一个 url,不需要发布),并且这个 url 当与选定的 rowids 一起调用时会删除来自第一个 url 的特定行详细信息并返回 null。
- 最后,第一个 url 数据(将通过调用带有 rowids 的第二个 url 来修改)必须在已经存在的表中更新。
如何更改此代码以将 rowid 发送到第二个 url 并调用该 url 以更新表。提前致谢!!
【问题讨论】:
-
在plunker中添加一些数据
-
@dgk: Url am using is from a local host.. 除了我在 plunker 中添加了所有代码。
-
根据您的回复创建一些硬编码数据。在 table.data 中设置。所以我可以在看到一些数据后提供帮助
-
$scope.selection.each(function (obj) { $scope.tableContent.splice(obj, 1) });在 remove 方法中使用它
-
plnkr.co/edit/WwDjn5MByX41SBAA8OUA?p=preview我更新了fork希望你能与你的代码集成。
标签: javascript angularjs