2016-10-28 25 views
1

The layout inside template solution doesn't workNativescript:錯誤:在列表模板中找到多個視圖!嵌套層次:0

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, 

line: 138, column: 8

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

line: 138, column: 15 Frame: function:'getSingleViewFromViewRef', file:'/data/data/org.nativescript.finlyng/files/app/tns_modules/nativescript-angular/directives/list-view-comp.js', line: 154, column: 12 Frame: function:'ListViewComponent.onItemLoading', file:'/data/data/org.nativescript.finlyng/files/app/tns_modules/nativescript-angular/directives/list-view-comp.js', line: 72, column: 25 Frame: function:'Observable.notify', file:'/data/data/org.nativescript.finlyng/files/app/tns_modules/data/observable/observable.js', line: 146, column: 32 Frame: function:'ListViewAdap

+1

確保你保存了你的文件(當以Stack佈局包裝時)然後重建應用程序。事實上,你的項目模板只能有一個根元素,並且錯誤不應該與現有結構一起出現 - 這裏是基本示例:https://github.com/NativeScript/nativescript-sdk-examples-ng/blob/master /app/ui-category/listview/creating-listview/creating-listview.component.html –

+1

@NickIliev保存並重建,錯誤仍然存​​在。 – moaglee

回答

0

這是很老,但我也有類似的問題。

我通過在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>