tabview 中的 ListView 不更新
ListView in tabview doesn't update
你好,我对 TabView 中的 listView 有一个很奇怪的问题。我整天都在解决这个问题,但没有结果。由于没有刷新 listView(ngZone 没有帮助),我必须在 listView 中以编程方式进行刷新。它有效,但问题是当我通过路由器从另一个页面转到此页面然后通过构造函数上一页注入时。
我有登录页面:
this.router.navigate(["/home"]);
并且在 home.component.ts 构造函数中看起来像:
constructor(ngZone: NgZone, private page: Page)
然后我试着打电话:
var listview:ListView= <ListView> page.getViewById("listView1");
但它返回未定义(如果登录页面不存在并且只有主页存在,它可以正常工作)。当我尝试从登录页面获取一些视图时,我得到了视图...
谁能告诉我哪里出了问题?我尝试了很多我发现的东西,但没有任何效果......谢谢你的回答。
编辑:
添加代码片段:
home.component.html
<GridLayout class="page">
<TabView height="100%" (selectedIndexChange)="onTabChanged($event)" class="content p-20" >
<ng-container *ngFor="let itema of objectKeys(site)" >
<StackLayout *tabItem="{title: itema}">
<ListView [id]="itema" class="list-group" [items]="getData(itema)" (itemTap)="onItemTap($event)">
<ng-template let-item >
<GridLayout class="list-group-item" rows="*" columns="auto, *">
<Label row="0" col="0" [text]="item.name"></Label>
</Image>
</GridLayout>
</ng-template>
</ListView>
</GridLayout>
</StackLayout>
</ng-container>
</TabView>
</GridLayout>
home.components.ts 部分:
ngOnInit(): void {
getJSON(url).then((r: any) => {
console.log(r);
this.ngZone.run(() => {
this.site = r;
});
//this part added because ngZone didn't work
var listview: ListView = <ListView>this.page.getViewById(objectKeys(this.site)[0]);
listview.refresh();
}, (e) => {
//TODO handle exception
console.log(e);
});
}
我认为问题的出现是因为 ListView 是动态构造的(刷新在 onTabChange 方法中也不起作用。)
我没有发现动态选项卡/ng-container 有任何问题。
这是一个 Playground sample 已经用 iOS 和 Android 测试过的。如果您仍然遇到问题,请更新 playground 示例,我们可以在其中重现您的问题。
你好,我对 TabView 中的 listView 有一个很奇怪的问题。我整天都在解决这个问题,但没有结果。由于没有刷新 listView(ngZone 没有帮助),我必须在 listView 中以编程方式进行刷新。它有效,但问题是当我通过路由器从另一个页面转到此页面然后通过构造函数上一页注入时。 我有登录页面:
this.router.navigate(["/home"]);
并且在 home.component.ts 构造函数中看起来像:
constructor(ngZone: NgZone, private page: Page)
然后我试着打电话:
var listview:ListView= <ListView> page.getViewById("listView1");
但它返回未定义(如果登录页面不存在并且只有主页存在,它可以正常工作)。当我尝试从登录页面获取一些视图时,我得到了视图...
谁能告诉我哪里出了问题?我尝试了很多我发现的东西,但没有任何效果......谢谢你的回答。
编辑: 添加代码片段: home.component.html
<GridLayout class="page">
<TabView height="100%" (selectedIndexChange)="onTabChanged($event)" class="content p-20" >
<ng-container *ngFor="let itema of objectKeys(site)" >
<StackLayout *tabItem="{title: itema}">
<ListView [id]="itema" class="list-group" [items]="getData(itema)" (itemTap)="onItemTap($event)">
<ng-template let-item >
<GridLayout class="list-group-item" rows="*" columns="auto, *">
<Label row="0" col="0" [text]="item.name"></Label>
</Image>
</GridLayout>
</ng-template>
</ListView>
</GridLayout>
</StackLayout>
</ng-container>
</TabView>
</GridLayout>
home.components.ts 部分:
ngOnInit(): void {
getJSON(url).then((r: any) => {
console.log(r);
this.ngZone.run(() => {
this.site = r;
});
//this part added because ngZone didn't work
var listview: ListView = <ListView>this.page.getViewById(objectKeys(this.site)[0]);
listview.refresh();
}, (e) => {
//TODO handle exception
console.log(e);
});
}
我认为问题的出现是因为 ListView 是动态构造的(刷新在 onTabChange 方法中也不起作用。)
我没有发现动态选项卡/ng-container 有任何问题。
这是一个 Playground sample 已经用 iOS 和 Android 测试过的。如果您仍然遇到问题,请更新 playground 示例,我们可以在其中重现您的问题。