angularjs - 删除我在模式上附加的内容
问题描述
我有一个模式,根据选择显示新数据。问题是,当我关闭模式时,它不会清除它只是附加在它上面的旧数据。理想情况下,我不会在每次按下关闭按钮时清除模式。这是我尝试过的,但它不起作用。
$scope.onCloseModal = function() {
table = angular.element('#table-services');
table.remove();
}
这是附加到 html 的循环。
angular.forEach($scope.payment_transaction_services,function(value,index) {
var tr = angular.element('#table-services').append
('<tr>' +
'<td>' + value.title + '</td>' +
'<td>' + value.delivered_by + '</td>' +
'<td>' + value.status + '</td>' +
'<td>' + value.delivery_date + '</td>' +
'</tr>'
);
})
这是我的模态。
<div id="view-service-status" class="modal fade role="dialog">
<div class="modal-dialog" role="document">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h2 class="modal-title">Service Status</h2>
</div>
<div class="modal-body">
<table class=" table table-bordered" id = "table-services">
<tr>
<th> <b> Service </b> </th>
<th> <b> Delivered By </b> </th>
<th> <b> Status </b> </th>
<th> <b> Delivered At </b> </th>
</tr>
</table>
</div>
<div class="modal-footer view-service-status">
<button type="button" class="btn btn-default" data-dismiss="modal" ng-click="onClose()" class="close">Close</button>
</div>
</div>
</div>
解决方案
发生这种情况是因为您只需删除并再次获得相同的元素而不做任何更改。在追加新数据之前尝试清空#table-services 元素。
像这样的东西:
var tr = angular.element('#table-services');
tr.empty();
angular.forEach($scope.payment_transaction_services,function(value,index) {
tr.append
('<tr>' +
'<td>' + value.title + '</td>' +
'<td>' + value.delivered_by + '</td>' +
'<td>' + value.status + '</td>' +
'<td>' + value.delivery_date + '</td>' +
'</tr>'
);
})
推荐阅读
- storybook - 如何在 Storybook 5 中设置网格单元格大小?
- java - JPA,删除子实体时删除实体
- javascript - 未捕获的类型错误:无法读取未定义的属性“ModelBufferGeometry”
- winforms - 如何使用上下文菜单关闭项禁用 KryptonPage 的删除按钮?
- html - 桌面停止时移动到一边的顶部导航栏?(引导程序)
- angular - 添加 StoreModule.forFeature(...) 后无法访问存储的数据
- java - Cloud Foundry:如何使用额外的 JVM 命令部署 Spring Boot 应用程序
- javascript - 有没有办法用 React native 录制音频并将其存储为波形文件?
- python - 如何在 AWS Glue 中正确重命名动态数据框的列?
- java - 在java中组合比较器