Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

直接 URL 传 page_index,直接跳转到具体页面 #4

Open
meetbill opened this issue Sep 20, 2020 · 1 comment
Open

直接 URL 传 page_index,直接跳转到具体页面 #4

meetbill opened this issue Sep 20, 2020 · 1 comment

Comments

@meetbill
Copy link
Owner

meetbill commented Sep 20, 2020

当前

URL

http://xxx:8855/#/app/canghai/mq_jobs?queue_name=default&registry_name=finished&page_size=15&page_index=15

发现后端请求顺序


2020-09-20 23:47:27	6514	httpgateway.py:243	xxx	7B90F7CF37BF5DB5	GET	/canghai/list_jobs	0.023511	OK	wangbin34	stat:	params:page_index:15,queue_name:default,registry_name:finished,page_size:15	error_msg:	res:
2020-09-20 23:47:27	6514	httpgateway.py:243	xxx	C94FDF021D9C2BB0	GET	/canghai/list_jobs	0.014473	OK	wangbin34	stat:	params:page_index:1,queue_name:default,registry_name:finished,page_size:15	error_msg:	res:
2020-09-20 23:47:27	6514	httpgateway.py:243	xxx	FF575FFCDBFCC3E0	GET	/canghai/list_jobs	0.006657	OK	wangbin34	stat:	params:page_index:1,queue_name:default,registry_name:finished,page_size:15	error_msg:	res:
  • 第一次 15 页,刷新了视图
  • 第二次 1 页,刷新了视图
  • 第三次 1 页,触发了 $scope.pageChanged

将 ui-router 从 0.2.15 升级到了 0.2.18

刷新浏览器时,变为了 2 次请求

2020-09-21 10:57:03	6514	httpgateway.py:243	xxx	96646C0E623928D5	GET	/canghai/list_jobs	0.007039	OK	wangbin34	stat:	params:page_index:12,queue_name:default,registry_name:finished,page_size:15	error_msg:	res:
2020-09-21 10:57:03	6514	httpgateway.py:243	xxx	2D9C0EE3E6604EFE	GET	/canghai/list_jobs	0.006614	OK	wangbin34	stat:	params:page_index:1,queue_name:default,registry_name:finished,page_size:15	error_msg:	res:
  • 第一次 15 页,刷新了视图
  • 第二次 1 页,触发了 $scope.pageChanged

从 $scope.pageChanged 的条件是 $scope.currentPage 从 15 变为 1 ,而这个 $scope.currentPage 从 15 跳转到 1 目前还没找到原因

猜测

目前猜测原因如下:

  • 渲染时先加载了 controller,显示为 15
  • html 中 <pagination> 指令加载,默认为 1 页,然后触发 $scope.pageChanged

网上寻求方案

angular-ui/bootstrap#5858

ui-bootstrap-pagination-resetting-current-page-on-initialization

解决方法

the issue is with totalItems and when I try to move to page 2/3/n, totalItems becomes 0 for a moment and in the process, currentPage value becomes 1 and I can't move to my desired page. So my trick is, before I call the data from server, I just set a bigger number as totalItems and after I receive data from server, I update totalItems.

$scope.totalItems = 1000;

即通过先提前初始化一个比较大的 totalItems 值

@meetbill
Copy link
Owner Author

备注

(1) 需要更新 ui-router 版本从 0.2.15 升级到 0.2.18
    (【沧海】不升级版本时,通过 $state.go 从 queue 页面跳转到消息列表时,也会出现刷新两次的情况)
(2) $scope.totalItems 设置为 1000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant