【问题标题】:How to access the item context inside RadListView tkListItemSwipeTemplate如何访问 RadListView tkListItemSwipeTemplate 中的项目上下文
【发布时间】:2018-02-06 08:38:54
【问题描述】:

使用 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 中的当前项目,以便我可以将标签的文本属性绑定到简短描述。目前我收到以下错误

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

【问题讨论】:

    标签: nativescript nativescript-angular


    【解决方案1】:

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

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

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

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

    这应该可以让你摆脱麻烦。希望对你有帮助:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-15
      • 2019-12-30
      • 2016-06-25
      相关资源
      最近更新 更多