【问题标题】:NativeScript RadListView indexNativeScript RadListView 索引
【发布时间】:2019-09-23 21:26:29
【问题描述】:

我使用的是 NativeScript 6.1.1,并且我有一个 RadListView,我希望在其中的每一行都有唯一的引用。我正在考虑的一种方法是,如果我可以获得一个索引字段,那么我可以拥有带有以下内容的“automationText”字段

name0
name1
name2

这是我当前的模板;

<RadListView automationText="listing"
             [items]="dataItems"
             [filteringFunction]="filterItems"
             pullToRefresh="true"
             (pullToRefreshInitiated)="onPullToRefreshInitiated($event)">

  <ng-template tkListItemTemplate let-item="item">
    <StackLayout orientation="vertical">
      <GridLayout class="itemContainer" rows="50,*" columns="*,100">

        <Label automationText="name" row="0" col="0" class="nameLabel" [text]="item.name"></Label>

      </GridLayout>
    </StackLayout>
  </ng-template>

</RadListView>

有可能做这样的事情吗?

        <Label automationText="name#{index}" row="0" col="0" class="nameLabel" [text]="item.name"></Label>

【问题讨论】:

  • 您可以通过 xpath 获取项目列表并单击特定索引。

标签: appium nativescript


【解决方案1】:

要获取索引,您可以将 let-i="index" 添加到 ng-template 并将其作为 automationText="name{{i}}" 使用

样本:

<RadListView [items]="_dataItems" [itemTemplateSelector]="templateSelector">
    <ng-template tkTemplateKey tkListItemTemplate let-item="item"
        let-i="index">
        <StackLayout>
            <Label automationText="name{{i}}"  text="name{{i}}"></Label>
        </StackLayout>
    </ng-template>
</RadListView>

【讨论】:

  • 谢谢伙计。我觉得 nativescript 文档中缺少一些实用的东西
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-06-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-10
  • 2017-09-09
  • 1970-01-01
相关资源
最近更新 更多