javascript - 为什么我的下一个和上一个控件在分页时无法获取正确的索引?我需要做哪些改变?
问题描述
在我的代码中,当您单击任何记录时,您将看到详细信息。在详细信息中有 2 个链接(上一个,下一个)导航到上一个 n 下一个记录。在第一页上它工作正常。但是,当我从分页导航到下一页并单击上一个 n 下一个时,它仍然采用第一页行索引,而上一个 n 下一个是从行而不是选择行发生的。
你可以在这里查看:https ://angular-ivy-hkrfyu.stackblitz.io/
nextRecord() {
let next = (this.currentIndex += 1);
if (next > this.allUserTableData.length - 1) {
this.currentIndex = 1;
return;
}
let nextRecord = this.allUserTableData[next];
this.userObj = nextRecord;
console.log(nextRecord, next);
}
previousRecord() {
let next = (this.currentIndex -= 1);
if (next < 0) {
this.currentIndex = 0;
return;
}
let nextRecord = this.allUserTableData[next];
this.userObj = nextRecord;
console.log(nextRecord, next);
}
<button (click)="previousRecord()">Previous</button> | <button (click)="nextRecord()">Next</button>
解决方案
我在里面添加了新参数viewuser()
<tr class="record-row" (click)="viewUser(user, i, filteredUsers, 5, page)"
在 viewUser() 里面
viewUser(user: any, index, filterData, itemsPerPage, currentPage) {
console.log(itemsPerPage, currentPage);
let currentPageIndex = currentPage;
let recordPerPageToShow = itemsPerPage;
let findCurrentRecordToSkip = (currentPageIndex - 1) * recordPerPageToShow;
let countIndex = findCurrentRecordToSkip + recordPerPageToShow;
console.log(
"filter-pagination",
filterData.slice(findCurrentRecordToSkip, countIndex)
);
this.isView = true;
console.log(user, index, filterData);
this.userObj = user;
this.currentIndex = index;
this.allUserTableData = filterData.slice(
findCurrentRecordToSkip,
countIndex
);
}
推荐阅读
- google-apps-script - 谁能建议提取电话号码的公式。从谷歌表中的这种类型的数据?
- sql-server - SSMS - SQLQuery 网格结果中缺少标题(列名)
- assembly - 这个 movabsq 指令有错误吗?
- flutter - 如何用颤动的 neucard 定位错误文本?
- sql - lite 到完整更新后 Laragon 数据丢失
- jsp - 拆分大表格 - JSP
- javascript - 使用 React Hooks 的依赖下拉列表
- windows - 当我尝试使用“react-native-dom”时出现错误--error Unrecognized command “dom”
- javascript - 如何通过正则表达式获取所有类名
- go - 继续在 Golang 中重试一个函数