【发布时间】:2018-09-18 13:27:44
【问题描述】:
我有一个 RadListView Nativescript + Angular 元素,我想通过滑动操作删除项目:
<RadListView [items]="stockList" id="listview" style="height: 100%; background-color: #f5f5f5;" swipeActions="true" pullToRefresh="true"
(pullToRefreshInitiated)="onPullToRefreshInitiated($event)"
(itemSwipeProgressEnded)="onSwipeCellFinished($event)"
(itemSwipeProgressStarted)="onSwipeCellStarted($event)"
(itemSwipeProgressChanged)="onCellSwiping($event)">
<ng-template let-item="item">
<GridLayout rows="*,*" colSpan="5" columns="*,2*,*,*" (tap)="onTap(item.name)">
<SVGImage col="0" row="0" rowSpan="2" class="pgrRating" [src]="pgrRating(item.PGR, item.raw_PGR)"></SVGImage>
<!-- TICKER -->
<Label row="0" col="1" horizontalAlignment="left" class="itemName" [text]="item.symbol"></Label>
<!-- COMPANY NAME -->
<Label row="1" col="1" horizontalAlignment="left" class="itemCompName" [text]="item.name"></Label>
<!-- LAST PRICE TODAY -->
<Label row="0" col="2" colSpan="2" horizontalAlignment="left" class="itemPrice"
[text]="'$' + (item.Last).toFixed(2)"
[ngClass]="item.Change == 0 ? 'black' : (item.Change > 0 ? 'green' : 'red')"></Label>
<Label style="color: #c00000" row="0" col="3" class="icon" text=""></Label>
<!-- $ CHANGE TODAY -->
<Label row="1" col="2" horizontalAlignment="left" class="itemChange"
[text]="item.Change.toFixed(2)"
[ngClass]="item.Change == 0 ? 'black' : (item.Change > 0 ? 'green' : 'red')"></Label>
<!-- % CHANGE TODAY -->
<Label row="1" col="3" horizontalAlignment="left" class="itemPriceChange"
[text]="item.Change > 0 ? ('(+' + item['Percentage '].toFixed(2) + '%)') : ('(' + item['Percentage '].toFixed(2) + '%)')"
[ngClass]="item.Change == 0 ? 'black' : (item.Change > 0 ? 'green' : 'red')"></Label>
</GridLayout>
</ng-template>
</RadListView>
问题是,我不确定将滑动模板放在哪里以保留“let-item ngFor”行为以获取该项目的索引。文档提到放置模板:
<GridLayout *tkListItemSwipeTemplate columns="auto, *, auto" class="gridLayoutLayout">
<StackLayout id="mark-view" col="0" class="icon" (tap)="onLeftSwipeClick($event)">
<Label text="mark" class="swipetemplateLabel" verticalAlignment="center" horizontalAlignment="center"></Label>
</StackLayout>
<StackLayout id="delete-view" col="2" class="" (tap)="onRightSwipeClick(item.index)">
<Label row="0" col="2" text="" class="icon swipeIcon" verticalAlignment="center" horizontalAlignment="center"></Label>
</StackLayout>
</GridLayout>
在<ng-template> 下,但如果这样做,我会在“项目”循环中丢失,然后不知道如何传递索引。如果我将滑动模板放在 ng-template 中以保留项目索引,那么列表会在模板所在的位置显示一个空白区域,因此我的列表不能占据视图的整个高度。
有什么建议吗?非常感谢!!
【问题讨论】:
-
如果您需要一个工作示例,请查看github.com/EddyVerbruggen/nativescript-pluginshowcase/blob/… - 您也可以从应用商店安装该应用并试一试(请参阅 repo 中的自述文件)。跨度>
标签: ios angular listview mobile nativescript