首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RadListView不显示项目

RadListView不显示项目
EN

Stack Overflow用户
提问于 2018-12-13 18:09:07
回答 1查看 300关注 0票数 1

在我的应用程序中实现RadListView有很多困难。根据文档,ListView接受项作为ObservableArray,但无论是使用该数组还是普通数组,都不会显示项。我在游乐场准备了一个示例应用程序

https://play.nativescript.org/?template=play-ng&id=39xE2X&v=11

组件是这样的:

代码语言:javascript
复制
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);
    }

}

和这样的模板:

代码语言:javascript
复制
<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中留下任何东西,但它仍然可以显示项目

EN

回答 1

Stack Overflow用户

发布于 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);

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53759400

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档