Mar*_* M. 3 javascript aurelia
我正在 aureliajs 框架中创建一个自定义组件并将其注入一个Router实例:
@inject(Router)
export class Pagination {
constructor(router) {
this.router = router;
}
}
Run Code Online (Sandbox Code Playgroud)
它将与列表视图模型一起使用以设置一些基本的分页。因此,我需要从活动路线中读取当前页码(看起来像:orders/:pageNum。我不知道该怎么做?我的意思是 - 我知道它可能应该放在Pagination附加方法中,但是如何做到这一点:pageNum参数?
在您的自定义元素中创建一个可绑定的属性。从活动路由中获取页码并将其绑定到自定义元素。例如:
import { bindable } from 'aurelia-framework';
@inject(Router)
export class Pagination {
@bindable page;
constructor(router) {
this.router = router;
}
}
Run Code Online (Sandbox Code Playgroud)
用法:
<pagination page.bind="page"></pagination>
Run Code Online (Sandbox Code Playgroud)
要获取活动路由中的页码,请使用activate()钩子:
activate(params) {
this.page = params.pageNum;
}
Run Code Online (Sandbox Code Playgroud)