首页 文章

获取Nativescript Telerik UI RadListView以在Angular中工作

提问于
浏览
3

TNS v2.5.0

我已将 LISTVIEW_DIRECTIVES 导入到我的app.module中,我的模板看起来像

<ActionBar title="Events"></ActionBar>
<StackLayout orientation="vertical">
    <RadListView [items]="events">
        <template tkListItemTemplate let-event="item">
            <StackLayout orientation="vertical">
            <Image [src]="'https:' + event.image" stretch="aspectFit"></Image>
            <Label [nsRouterLink]="['/event', event.id]" [text]="event.title"></Label>
            </StackLayout>
        </template>
    </RadListView>
</StackLayout>

但这显示什么,但改为常规 ListView 工作正常 .

如果我尝试 GridLayout 就好

<ActionBar title="Events"></ActionBar>
<GridLayout>
    <RadListView [items]="events">
        <template tkListItemTemplate let-event="item">
            <StackLayout orientation="vertical">
            <Image [src]="'https:' + event.image" stretch="aspectFit"></Image>
            <Label [nsRouterLink]="['/event', event.id]" [text]="event.title"></Label>
            </StackLayout>
        </template>
    </RadListView>
</GridLayout>

该应用程序因错误而崩溃

file:///app/tns_modules/nativescript-telerik-ui/listview/listview.js:1034:104:JS ERROR TypeError:undefined不是对象(评估'itemViewDimensions.measuredWidth')2月5日11:40:53 Marcuss-iMac com.apple.CoreSimulator.SimDevice.1A8C1E25-DAC0-4BA0-822E-5A6F731F1CD7.launchd_sim [31919](UIKitApplication:org.nativescript.t4g [0x7b2a] [36194]):由于分段故障退出服务:11

不确定我是否错过了在某处导入的东西,但文档非常粗略,因此很难确定并查看示例

5 回答

  • 0

    LISTVIEW_DIRECTIVES用于使用Javascript的Nativescript .

    对于Angular2:

    安装插件 tns plugin add nativescript-telerik-ui 之后 rebuild 与tns运行android以获得新的插件工作 .

    module.ts 添加:

    import from "nativescript-telerik-ui/listview/angular";

    并在同一个文件中:

    在@NgModule imports 添加: NativeScriptUIListViewModule,

    它会准备好的 .

  • 0

    以下是我如何使用它 .

    • 创建一个共享指令模块,并且只在那里定义RadListView指令 .

    应用程序/共享/共享directives.module.ts

    import {NgModule} from "@angular/core";   
    import {LISTVIEW_DIRECTIVES} from "nativescript-telerik-ui/listview/angular";
    
    @NgModule({
      declarations: [
        LISTVIEW_DIRECTIVES
    ],
    exports: [
        LISTVIEW_DIRECTIVES
    ]
    })
    export class SharedDirectivesModule {}
    
    • 在您使用RadListView的任何功能/子模块中导入此共享指令模块 .

    这是一个例子 .

    应用程序/事件/ events.module.ts

    import {SharedDirectivesModule} from "../shared/shared-directives.module";
    ...
    
    @NgModule({
    imports: [
        ...
        SharedDirectivesModule,
        ...
    ],
    ...
    })
    export class EventsModule {}
    

    应用程序/事件/ events.component.html

    <GridLayout>
      <RadListView [items]="events">
        <template tkListItemTemplate let-event="item">
            <StackLayout orientation="vertical">
            <Image [src]="'https:' + event.image" stretch="aspectFit"></Image>
            <Label [nsRouterLink]="['/event', event.id]" [text]="event.title"></Label>
            </StackLayout>
        </template>
      </RadListView>
    </GridLayout>
    
  • 0

    我需要'm not sure it',但我在项目中有 RadListView 并且 ListViewLinearLayout 作为其子项之一:

    <RadListView [items]="listViewItems">
      <ListViewLinearLayout tkListViewLayout scrollDirection="Vertical"></ListViewLinearLayout>
      <template tkListItemTemplate let-item="item">
        <YourStuff></YourStuff>
      </template>
    </RadListView>
    

    你也在你的app模块中将 LISTVIEW_DIRECTIVES 添加到 declarations 列表中了吗?

  • 2

    我遇到了同样的问题 . 我在app模块中导入并声明了LISTVIEW_DIRECTIVES . 包含ListView的组件在子模块中声明 . 当我将LISTVIEW_DIRECTIVES的decalaration移动到子模块时,错误就消失了 .

  • 1

    你需要设置列表的高度,默认情况下高度为0px;

    <RadListView [items]="dataItems" height="300">
    

相关问题