【问题标题】:NativeScript error. More than one view found in list templateNativeScript 错误。在列表模板中找到多个视图
【发布时间】:2016-10-25 13:44:59
【问题描述】:

我有这样的 ListView

<ListView [items]="groceryList" row="1" class="small-spacing" [class.visible]="listLoaded">
    <template let-item="item" columns="*, auto" >
      <Label [text]="item.name" class="medium-spacing"></Label>      
    </template>
  </ListView>

我想添加图片按钮。所以我只是将columns="*, auto" 添加到templatecol="0" 给标签,col="1" 给我的Image

 <ListView [items]="groceryList" row="1" class="small-spacing" [class.visible]="listLoaded">
    <template let-item="item" columns="*, auto" >
      <Label [text]="item.name" class="medium-spacing" col="0"></Label>
      <Image src="res://delete" (tap)="delete(item.id)" col="1"></Image>      
    </template>
  </ListView>

运行模拟器后出现错误:

有什么想法为什么会发生这种情况以及如何解决?

【问题讨论】:

  • 您应该在ListView 模板内和Layout 内为主容器添加StackLayoutGridLayout ,以添加ImageLabel。例如&lt;StackLayout&gt;&lt;Label [text]="item.name" class="medium-spacing" &gt;&lt;/Label&gt; &lt;Image src="res://delete" (tap)="delete(item.id)"&gt;&lt;/Image&gt;&lt;/StackLayout&gt;
  • @NikolayTsonev 我应该取出template 吗?
  • 您不必删除template ,您应该在其中添加布局

标签: android nativescript angular2-nativescript


【解决方案1】:

innside &lt;template&gt; 只允许一个元素,你有两个。 改为在 &lt;template&gt; 内添加一个 GridLayout,然后在其中添加元素。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-18
    • 2020-12-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多