在我的应用程序中实现RadListView有很多困难。根据文档,ListView接受项作为ObservableArray,但无论是使用该数组还是普通数组,都不会显示项。我在游乐场准备了一个示例应用程序
https://play.nativescript.org/?template=play-ng&id=39xE2X&v=11
组件是这样的:
import { Component, ViewChild, OnInit, ChangeDetectorRef, ElementRef } from "@angular/core";
import { GestureTypes, PanGestureEventData, TouchGestureEventData } from "tns-core-modules/ui/gestures";
import { ObservableArray } from "tns-core-modules/data/observable-array";
@Component({
selector: "ns-app",
moduleId: module.id,
templateUrl: "./app.component.html",
})
export class AppComponent implements OnInit {
public gridData = []; //new ObservableArray<any>();
constructor(
private cd: ChangeDetectorRef
) {
this.feedTestData();
}
ngOnInit() {
}
ngAfterViewInit() {
}
public detectChanges() {
this.cd.detectChanges();
}
private feedTestData() {
let data = [
{
description: 'line 1',
},
{
description: 'line 2',
},
];
this.gridData.splice(0, 0, data);
}
}和这样的模板:
<GridLayout tkExampleTitle tkToggleNavButton>
<RadListView [items]="gridData">
<ng-template tkListItemTemplate let-item="item">
<StackLayout orientation="vertical">
<Label [text]="description"></Label>
</StackLayout>
</ng-template>
</RadListView>
</GridLayout>更让我困惑的是,在我的实际应用程序中,RadListView显示了一些东西,但它是自己做的,完全忽略了我的模板。从字面上讲,我可以不在RadListView中留下任何东西,但它仍然可以显示项目

发布于 2018-12-14 08:58:39
我已经更新了你的游乐场,现在它正在工作。https://play.nativescript.org/?template=play-ng&id=39xE2X&v=12
您正在尝试访问ng-template中的描述,而它应该是item.description
<Label [text]="item.description"></Label>
同样出于测试目的,我将从您的数据创建Onservable数组。feedTestData函数中的this.gridData = new ObservableArray(data);。
https://stackoverflow.com/questions/53759400
复制相似问题