typescript - 为什么修改后变量没有改变?
问题描述
我有分页课程:
export class Pagination {
public localPagination(type: IPaginationLocal): void {
this.paginationType = type;
this.fetchData();
}
public fetchData() {
this.paginationType.data = this.paginationType.data.slice(this.from, this.to);
}
}
使用:
this.plans = [1,2,3,4,5,6,7,8,9,10];
this.pagination.localPagination({
data: this.plans,
type: modePagination.LOCAL
});
console.log(this.plans);// It must be sliced
如您所见,我将变量传递this.plans
给类this.pagination.localPagination()
::
然后类在方法中制作切片输入数据fetchData()
。
分页执行后,我这样做:
console.log(this.plans);
它应该返回切片数组,但返回初始数组this.plans
。
解决方案
你永远不会改变
这个.plans
你正在改变变量
this.paginationType.data
推荐阅读
- c# - 如何更改自定义 configSections 变量的值?
- reactjs - 创建辅助函数以在我的 redux reducer 代码中重复使用以改变状态
- python-3.x - 如何将工作簿传播到另一个工作簿的工作表集使用 openpyxl
- windows - 使用powershell脚本复制文件夹内容保留文件夹结构
- node.js - 查询 better-sqlite3 以获取记录数据
- c# - Xamarin Firebase 推送通知 - 在 Android 上收到间歇性重复推送通知
- python - 熊猫时间戳到 datetime.datetime()
- docker - 寻找一个示例 docker-compose 文件让 traefik 反向代理容器和非容器服务
- amazon-web-services - 使用 CodePipeline 从 VPC 调用 Lambda 失败并出现超时
- xquery - 条件组合索引:当有多种十进制类型的索引时,无法查询到想要的结果