在使用get和使用Angular进行订阅时,如何忽略表中的第一条记录?使用以下代码:-
getAdmins() {
this.data = [];
this.api.getAdminList()
.subscribe(
data => {
this.data = data;
if (this.isFirstLoad) {
this.isFirstLoad = false;
this.dtTrigger.next();
}
}
);
}
我的数据布局如下:-
我想忽略管理员记录,但是从x先生开始显示记录。
答案 0 :(得分:1)
getAdmins() {
this.data = [];
this.api.getAdminList()
.subscribe(
data => {
this.data = data.shift(); //The shift() command will remove the first element of the array
}
);
}
答案 1 :(得分:1)
您可以尝试使用阵列接头
<li>
或尝试反转数组,然后弹出最后一项
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar bg-light">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="index.php">Main</a>
</li>
<li class="nav-item">
<a class="nav-link" href="page1.php">Page 1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="page2.php">Page 2</a>
</li>
<li class="nav-item">
<a class="nav-link" href="page3.php">Page 3</a>
</li>
</ul>
</nav>
<br>
<div class="container-fluid" id="output">
THE CONTENT FROM ANOTHER PAGE THAT'LL LOAD HERE
</div>
</div>
</body>
</html>
答案 2 :(得分:0)
您是否考虑过使用拼接器?
this.data = [];
this.api.getAdminList()
.subscribe(
data => {
this.data = data.length > 1 ? data.splice(0, 1) : [];
}
);
答案 3 :(得分:0)
尝试:
this.api.getAdminList().pipe()
.subscribe(
data => {
this.data = data.splice(1);
}
);