1

概述

Nativescript radListView 不会在 ios 和 android 操作系统上显示来自组件的绑定项。
操作栏和通常的 ListView 显示数据,但 radlistview 不显示。控制台显示没有错误。但是我看到下一个存储库中的 RadListView 可以工作-> https://github.com/telerik/nativescript-ui-samples-angular

环境

我的开发环境如下。

os: macOS sierra 10.12.6
node : v6.12.0
npm : 3.10.10
nativescript 和其他可以在 package.json 之后看到

考虑

我似乎这个问题是关于这些......
但我无法细化。

  1. 角度指令
  2. 初始化一个可观察数组

代码

在“tns create ui-test --ng”之后,我在 Angular 上实现了 RadListView,如下所示。

零件

export class ItemsComponent implements OnInit {
    private _dataItems: ObservableArray<Item>;

    constructor() {
    }

    get dataItems(): ObservableArray<Item> {
        return this._dataItems;
    }

    ngOnInit() {
        this._dataItems = new ObservableArray([
            { id: 1, name: "Ter Stegen", role: "Goalkeeper" },
            { id: 3, name: "Piqué", role: "Defender" },
            { id: 4, name: "I. Rakitic", role: "Midfielder" }
        ]);
    }
}

html

<ActionBar title="My App" class="action-bar">
</ActionBar>

<GridLayout>
    <RadListView [items]="dataItems">
        <ng-template let-item="item">
            <StackLayout>
                <Label class="nameLabel" text="text"></Label>
                <Label class="nameLabel" [text]="item.name"></Label>
                <Label class="descriptionLabel" [text]="item.role"></Label>
            </StackLayout>
        </ng-template>
    </RadListView>
</GridLayout>

包.json

{
  "description": "NativeScript Application",
  "license": "SEE LICENSE IN <your-license-filename>",
  "readme": "NativeScript Application",
  "repository": "<fill-your-repository-here>",
  "nativescript": {
    "id": "org.nativescript.uitest",
    "tns-ios": {
      "version": "3.3.0"
    }
  },
  "dependencies": {
    "@angular/common": "~5.0.0",
    "@angular/compiler": "~5.0.0",
    "@angular/core": "~5.0.0",
    "@angular/forms": "~5.0.0",
    "@angular/http": "~5.0.0",
    "@angular/platform-browser": "~5.0.0",
    "@angular/platform-browser-dynamic": "~5.0.0",
    "@angular/router": "~5.0.0",
    "nativescript-angular": "5.0.0",
    "nativescript-fresco": "^3.0.2",
    "nativescript-intl": "^3.0.0",
    "nativescript-pro-ui": "3.3.0",
    "nativescript-unit-test-runner": "^0.3.2",
    "rxjs": "^5.5.2",
    "tns-core-modules": "3.4.0",
    "zone.js": "~0.8.2"
  },
  "devDependencies": {
    "nativescript-dev-typescript": "~0.5.0",
    "typescript": "~2.4.2"
  }
}
4

3 回答 3

5

我确实得到了你的代码并放入了 home.component 在 tns 创建 uitest --ng 然后 tns 插件添加 nativescript-ui-listview tns 平台删除 android tns 平台添加 android tns 构建 android tns 运行 android

如果您不要忘记在 home.module.ts 中导入此模块,它会起作用:NativeScriptUIListViewModule

import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
import { NativeScriptCommonModule } from "nativescript-angular/common";
import { NativeScriptUIListViewModule } from "nativescript-ui-listview/angular";

import { HomeRoutingModule } from "./home-routing.module";
import { HomeComponent } from "./home.component";

@NgModule({
  imports: [
    NativeScriptCommonModule,
    HomeRoutingModule,
    NativeScriptUIListViewModule
],
declarations: [
    HomeComponent
],
schemas: [
    NO_ERRORS_SCHEMA
]
})
export class HomeModule { }

用这个 item.model.ts

export class Item {
  id: number;
  name:string;
  role: string;
}

重要的

在另一个项目中,直到我在 app.module.ts 中添加这些行之后它才起作用

import { NativeScriptUIListViewModule } from "nativescript-ui-listview/angular/listview-directives";

@NgModule({
imports: [
    ...
    NativeScriptUIListViewModule
于 2018-12-01T16:07:02.033 回答
0

你试过_dataItems代替dataItems吗?看起来您已经定义了一个 itemsource 并在没有_RadListView 的情况下引用了它。

于 2018-01-04T23:56:25.220 回答
0

我自己解决了。RadListView 需要一个 getter 和一个 ObservableArray 实现,以及正确的 html 编码。我没有填写行之类的参数。

但我不明白如何很好地使用 radListView。现在我遇到了带有另一个 GridLayout 的 radListView 布局的麻烦。

于 2018-01-12T14:30:43.957 回答