- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我创建了一个表来显示从数据库中获取的数据。获取数据的 TS 部分类似于:
this._appService.getVisitData().subscribe((data) => {
this.checkinTemp = data;
// Calling the DT trigger to manually render the table
this.dtTrigger.next();
});
表格生成,我添加了编辑和删除功能,我的 View 代码:
<table datatable [dtOptions]="dtOptions" [dtTrigger]="dtTrigger" class="row-border hover">
<thead>
<tr>
<th>ID</th>
<th>Visitor Name</th>
<th>Department</th>
<th>Purpose</th>
<th>Schedule Date Time</th>
<th>Entry Source</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let data of checkinTemp">
<td>{{data.id}}</td>
<td>
<a (click)="viewCheckinData(data)"> {{data.f_name}} {{data.l_name}} </a>
<span>
<a (click)="editCheckinData(data)">Edit</a>
<a (click)="confirmDelete(data)">Delete</a>
</span>
</td>
<td>
<span *ngIf="data.department == null || data.department == ''">N/A</span>
<span *ngIf="data.department !== null ">{{data.department}}</span>
</td>
<td>
<span *ngIf="data.purpose == null || data.purpose == ''">N/A</span>
<span *ngIf="data.purpose !== null ">{{data.purpose}}</span>
</td>
<td>{{data.pre_check_in | date:'short'}}</td>
<td>{{data.creator_id}}</td>
</tr>
</tbody>
</table>
<p-confirmDialog header="Confirmation" icon="fa fa-question-circle" width="425"></p-confirmDialog>
现在,当用户按下删除时,confirmDelete(data)
被调用。 TS文件中的函数:
confirmDelete(item) {
this.confirmationService.confirm({
message: 'Are you sure you want to delete this Visitor?',
header: 'Confirmation',
accept: () => {
this._appService.deleteCheckin(item.id).subscribe(res => {
// Splice Or something so the page doesnt reload but the data gets removed from the view.
this.flashMsg.flashMsg('success', 'Deleted', 'Visitor has been deleted.');
},
err => {
this.flashMsg.flashMsg('error', 'Error', 'Visitor has not been deleted.');
});
},
reject: () => {
},
});
}
到目前为止,当我删除数据时,数据被删除并弹出确认消息,但数据仍显示在 View 中,直到页面重新加载。有没有办法在不加载页面的情况下从表中删除数据?我查找了 splice 但没有在代码中使用它。
最佳答案
从服务器成功删除项目后,您可以使用 splice(...)
将其从数组中删除,如下所示:
const index = this.checkinTemp.indexOf(item);
this.checkinTemp.splice(index, 1);
关于angular - 如何在 Angular 5 中使用拼接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49933001/
.splice() 方法的基本问题,以及如何最好地从数组中删除元素。 我想使用 .splice() 从数组中删除一个项目,但是当我这样做时,我希望返回原始数组 减去 删除的元素。 .splice()
我正在过滤同位素库。单击按钮会添加到称为过滤器的数组中。这是正常工作的,但是当用户单击事件按钮时,我希望从数组中删除过滤的类别。由于某种原因,事实并非如此。 这是特定的代码: if($(this).h
几个月前,我将一个 Subversion 存储库转换为 Mercurial,结果在我的修订历史中留下了两个毫无意义的空白。我试图弄清楚我是否可以拼接间隙,但我一直无法让工具精确地完成我想要的。 在项目
我制作简单的射击游戏,但有一个问题(有时): GIF Game problem 3颗子弹被移除(但只有一颗子弹相撞)。子弹和敌人(蓝色方 block )位于一个数组中(var objects = []
假设我们在 JavaScript 中有两个数组,[3,4,7] 和 [5,6]。 在不排序或使用 .apply 的情况下,将 [5,6] 插入索引 2 处的 [3,4,7] 的最佳方式是什么实现结果数
我试图在从数组中删除项目时添加纸质警报对话框,但我似乎无法理解这是如何工作的。 我现在可以使用以下功能,无需对话框: _delete(e) { var index = this.t
我正在尝试使用 splice() 从 jQuery 对象中删除元素. 但是,最终发生的情况是所有其他项目都被删除。我假设这是由于使用 splice 重新索引造成的。 我要淡入每个 所以我需要从顶部开始
这是我尝试从数组中动态删除一个值的尝试 $('.btn-remove').click(function() { var players = ["compare","13076","13075"
我正在考虑在 Visual Studio 2008 上使用 OpenCV 2.3.1 实时拼接来自 2 个或更多(目前可能是 3 或 4 个)摄像头的图像。 但是,我很好奇它是如何完成的。 最近研究了
我在将两个数组拼接在一起时遇到问题。假设我有两个数组: a = array([1,2,3]) b = array([4,5,6]) 当我执行 vstack((a,b)) 时,我得到了 [[1,2,3]
我拼接 css 文件以提高性能。 现在我想包含一个 minify 函数,如下所示。我该如何合并它? function minify( $css ) { $css = preg_replace(
我有两个 matlab 向量。第一个有 N 个元素,另一个有 k*N。我知道 k 是什么,我想拼接列表,使第一个向量中的每个元素出现在下一个向量中相应的 k 元素之前。例如: k = 3 x = [1
我有以下上下文: https://jsfiddle.net/eqntaqbt/2/ obj.forEach(function(user, index){ var userName = user
假设你有一个像这样的数组: var arr= [{id:121, v:'a'}, {id:232, 'b'}]; 你需要找到 id: 232 并删除它,所以你可以这样做: for (var i = a
似乎是通过 建立报价语法非常低效。例如创建一个整数列表 let q1 = List.foldBack (fun n acc -> ) [1..100000] Real: 00:00:05.714,
我正在为一家希望为其用户创建服务的公司开发应用程序。该公司目前提供时长约为 1.5 小时的视频,他们想要集成的服务是让用户能够“录制”这个较大视频的剪辑,以创建本质上的精彩片段。此服务的最终结果将是
splice 当 OFFSET 在数组中但 LENGTH 的末尾超过数组末尾时,是否可以? 最佳答案 易于尝试。 $ perl -wE' my @a = "a".."e"; my @b =
以前从未使用过 Tkinter,我不太确定如何使用它或它是如何工作的。 Windows IDLE Shell。 import time from tkinter import * input("Pre
这里是 Javascript 新手 -- 我有以下数组: var group = ({ one: value1, two: value2, three:
我的屏幕上打印了以下行: Would you like to pay €xx to POS_ID Latte X 1....€2.50-Salad X 1....€4.00-Wrap X 1..
我是一名优秀的程序员,十分优秀!