首页 文章

如何让* ngFor在Nativescript中使用ObservableArray?

提问于
浏览
0

ObservableArray 适用于 <ListView [items]="feedsComments" ,其中 feedsComments 是NativeScript中的 ObservableArray .

但当我用以下内容替换 ListView 时:

<StackLayout *ngFor="let item of feedsComments">
</StackLayout>

它会抛出以下错误:

ERROR Error: Cannot find a differ supporting object '[object Object],[object Object]' of type 'object'.
NgFor only supports binding to Iterables such as Arrays.

1 回答

  • 0
    <StackLayout *ngFor="let item of feedsComments._array" height="100" width="100">
        <Label [text]="item.someField"></Label> 
    </StackLayout>
    

    丑陋,但它的工作原理 . 似乎该类可以使用getItems()方法 . 但是有一个getItem(i)来获取数组中的特定项 .

相关问题