作者hope0330 (MMMM)
看板Ajax
标题Re: [问题] anglural 新手问题...
时间Sun May 29 02:34:09 2016
不好意思第一次发文,所以再重新发一次!
我想问的问题是,我想删掉列表出来的项目,
画面可以删除,但是後端接收不到。
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);
})
}
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 36.226.218.32
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Ajax/M.1464460451.A.9FF.html
1F:推 No: var id = $scope.list.id; 看起来怪怪的 05/29 02:40
2F:→ No: 是想写 var id = $scope.list.splice(idx, 1)[0].id; 吗? 05/29 02:42
3F:推 aaa7513231: log(id)看你有没有正确传给後端,然後测 05/29 09:30
4F:→ aaa7513231: 试资料给後端看能不能删除,就知道是前端 05/29 09:30
5F:→ aaa7513231: 试资料给後端看能不能删除,就知道是前端 05/29 09:30
6F:→ aaa7513231: 有问题题还是後端有问题 05/29 09:30
7F:→ hope0330: console 出来是正确的选到要删除的ID,但是变成画面 05/29 15:49
8F:→ hope0330: 画面不会改变删掉的还是在上面但没有错误 05/29 15:50
9F:推 ccvs: 你文章里面说画面可以正常删除 可是推文又说是画面无法删除 05/30 01:25
10F:→ ccvs: 都几? 05/30 01:25
11F:推 conanist: 你先把後端MARK,然後你画面上可以正常删除资料吗? 06/07 17:54
12F:→ conanist: 然後$http.delete 这行真的有去删後端的资料吗 06/07 17:56
13F:→ conanist: 试完在回来PO一下结果 06/07 17:57