Nativescript:错误:在列表模板中找到多个视图!嵌套级别:0

时间:2016-10-28 13:57:38

标签: nativescript angular2-nativescript

The layout inside template solution doesn't work

list.html

<ActionBar title="View Team Members">
    <NavigationButton text="Back" android.systemIcon="ic_menu_back"></NavigationButton>
</ActionBar>
<GridLayout>
    <ListView [items]="teamList" class="small-spacing">
        <template let-item="item">
            <StackLayout>
              <Label [text]="item.name" class="medium-spacing"></Label>
              <Label [text]="item.email" class="medium-spacing"></Label>
            </StackLayout>
        </template>
    </ListView>
</GridLayout>

相同的错误跟踪:

com.tns.NativeScriptException: 
Calling js method getView failed

Error: More than one view found in list template! Nesting level: 0
File: "/data/data/org.nativescript.finlyng/files/app/tns_modules/nativescript-angular/directives/list-view-comp.js,
     

行:138,列:8

StackTrace: 
  Frame: function:'getSingleViewRecursive', file:'/data/data/org.nativescript.finlyng/files/app/tns_modules/nativescript-angular/directives/list-view-comp.js',
     

行:138,栏目:15         框架:function:'getSingleViewFromViewRef',file:'/ data / data / org.nativescript.finlyng / files / app / tns_modules / nativescript-angular / directives / list-view-comp.js',   line:154,column:12         框架:功能:'ListViewComponent.onItemLoading',file:'/ data / data / org.nativescript.finlyng / files / app / tns_modules / nativescript-angular / directives / list-view-comp.js',   line:72,column:25         框架:功能:'Observable.notify',文件:'/ data / data / org.nativescript.finlyng / files / app / tns_modules / data / observable / observable.js',   line:146,column:32         框架:功能:'ListViewAdap

1 个答案:

答案 0 :(得分:1)

这已经很老了,但我遇到了类似的问题。

我通过将标签嵌套在GridLayout中来修复它。在我的情况下这样的事情:

<GridLayout rows="auto, *">
  <ListView [items]="newsList" row="1" class="news">
    <ng-template let-item="item">
      <GridLayout rows="auto, *">
        <Image [src]="item.image"></Image>
        <Label [text]="item.title" class="news__item"></Label>
      </GridLayout>
    </ng-template>
  </ListView>
</GridLayout>