首页 文章

如何访问RadListView tkListItemSwipeTemplate中的项上下文

提问于
浏览
0

使用NativeScript 3 Angular 5 .

我需要允许用户在RadListView中刷一个项目以显示关于该项目的简短描述 .

<RadListView 
        [items]="featuredVideos"
        pullToRefresh="true" 
        selectionBehavior="None"
        (itemSwipeProgressStarted)="onSwipeCellStarted($event)" 
        swipeActions="true" 
        (pullToRefreshInitiated)="onPullToRefreshInitiated($event)">
        <ng-template tkListItemTemplate let-item="item">
            <VideoComponent [video]="item"></VideoComponent>
        </ng-template>
        <ng-template tkListItemSwipeTemplate let-item="item">
            <GridLayout columns="*, 500" class="gridLayoutLayout">
                <StackLayout id="short-desc" col="1">
                    <Label [text]="item.shortDescription" class="body" verticalAlignment="center" horizontalAlignment="center"></Label>
                </StackLayout>
            </GridLayout>
        </ng-template>
    </RadListView

我希望能够访问 tkListItemSwipeTemplate 中的当前项目,以便我可以将标签的text属性绑定到简短描述 . 目前我收到以下错误

JS: ERROR TypeError: Cannot read property 'shortDescription' of undefined

1 回答

  • 0

    我知道这个问题现在有点老了,但对于那些来这里寻找答案的人来说,我已经设法解决了这个问题 . 将您的标签文本绑定到不同的值,即:

    <Label [text]="myLabelText"...
    

    然后在你的onSwipeCellStarted回调中,你可以使用ListViewEventData参数的index属性并适当地设置'myLabelText',例如:

    onSwipeCellStarted(args: ListViewEventData) {
       ...
       this.myLabelText = featuredVideos[args.index].shortDescription;
    }
    

    这应该让你摆脱困境 . 希望能帮助到你 :)

相关问题