不好意思第一次发文,所以再重新发一次!
我想问的问题是,我想删掉列表出来的项目,
画面可以删除,但是后端接收不到。
HTML部分:
<body>
<div ng-controller="firstCtrl">
书名:<input type="text" ng-model="name" placeholder="输入书名">
作者:<input type="text" ng-model="author" placeholder="输入作者">
<button type="button" ng-click="add()">新增</button>
<button type="button" ng-click="showList()">列出</button>
<table class="table table-striped" >
<tr colspan="5">
<td></td>
<td>ID</td>
<td>书名</td>
<td>作者</td>
<td></td>
</tr>
<tr ng-repeat="data in list">
<td><a href="" ng-click="remove($index)">X</a></td>
<td>{{data.id}}</td>
<td><span ng-hide="isShow"></span>
<span>
<input ng-show="isShow" type="text" ng-model="nameEdit" >
</span>
</td>
<td>{{data.author}}</td>
<td>
<button type="button" ng-click="editShow(data)">
<span ng-hide="isShow">修改</span>
<span ng-show="isShow">确认</span>
</button>
<button type="button">取消</button>
</td>
</tr>
</table>
<button ng-hide="clear" type="button" ng-click="rset()">全部清除</button>
</div>
JS部分:
$scope.list = []
$scope.clear = true;
$scope.showList = function() {
$http({
url: 'http://localhost:2000/book',
method: 'GET',
}).then(function(success_response) {
console.log(success_response);
$scope.list = success_response.data;
}, function(err_response) {
console.log(err_response);
})
if ($scope.clear = true) {
$scope.clear = false;
}
}
//删除
$scope.remove = function(idx) {
$scope.list.splice(idx, 1)
var id = $scope.list.id;
$http.delete('http://localhost:2000/book/', { id: id }).then(function(res) {
$scope.showList(res);
console.log(idx);
})
}
作者:
No (you stay there)
2016-05-29 02:40:00var id = $scope.list.id; 看起来怪怪的是想写 var id = $scope.list.splice(idx, 1)[0].id; 吗?
log(id)看你有没有正确传给后端,然后测试资料给后端看能不能删除,就知道是前端试资料给后端看能不能删除,就知道是前端有问题题还是后端有问题
楼主: hope0330 (MMMM) 2016-05-29 15:49:00
console 出来是正确的选到要删除的ID,但是变成画面画面不会改变删掉的还是在上面但没有错误
作者:
ccvs (kisS x Sis)
2016-05-30 01:25:00你文章里面说画面可以正常删除 可是推文又说是画面无法删除都几?
作者: conanist (QQ) 2016-06-07 17:54:00
你先把后端MARK,然后你画面上可以正常删除资料吗?然后$http.delete 这行真的有去删后端的资料吗试完在回来PO一下结果