gpt4 book ai didi

javascript - 如何使用angular js从表中删除一行?

转载 作者:行者123 更新时间:2023-11-30 14:56:45 25 4
gpt4 key购买 nike

我正在使用 Angular http 服务执行 DELEET 操作,它工作正常,删除数据记录后我还必须从表中删除该行。

下面是我的代码

$scope.DeleteSchedule = function (recordId) {
var v =$window.confirm('Are you sure you want to delete ?');
if (v == true) {
var row = '#row' + recordId;
var table = 'table #tbl_Schedule_Delete tr ' + row;
$http({
url: '@Url.Action("DeleteSchedule", "Admin")',
method: "DELETE",
params: {
recordId: recordId
}
}).then(function mySuccess(response) {
alert('Row Deleted Successfully');
angular.element(document.querySelector(table)).remove();
//$('table #tbl_Schedule_Delete tr' + row).remove();
}, function myError(response) {
$window.alert('Warning! It failed.');
});
}
}

引用 jQuery remove() 似乎什么都不做

value of variable table will be 'table #tbl_Schedule_Delete tr #row35'

angular.element(document.querySelector(table)).remove();

我检查了控制台日志,没有错误或警告。如何在 Angular JS 中做到这一点

更新 1:下面是表格标记

<tr id="row34" role="row" class="odd">
<td id="delete34" class="sorting_1">
<a id="deletebtn_34" ng-click="DeleteSchedule('34')"><i class="fa fa-times fa-lg" aria-hidden="true" style="color:#e90029"></i></a>
</td>
<td>34</td>
<td>11956</td>
<td>Tota Ram</td>
<td>04-10-2017</td>
<td>02-12-2017</td>
<td>Haryana</td>
<td>Badaun</td>
<td>03-11-2017</td>
</tr>

最佳答案

我不会使用 angular.element 删除该行,而是使用 ng-if 或 ng-show 显示/隐藏该行。

<tr id="row34" role="row" class="odd" ng-show="!deleted[34]">

结合:

在你的 Controller 中删除后:

scope.deleted[recordId] = true;

关于javascript - 如何使用angular js从表中删除一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47131796/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com