将ObservableArray传递到“模型”对话框参数,显示RadListView数据具有[Object Object]

时间:2018-12-10 11:48:37

标签: angular typescript nativescript nativescript-angular radlistview

我已经将Observable数组传递给模式对话框参数。打开模式对话框时,我从radlistview中获取了一个[object Object]值。

但是如果我使用listview可以正常工作。只有使用radlistview我必须解决此问题。

HomeComponent.ts:

 public obsArr: ObservableArray<App>;
    ngOnInit(){
        this.obsArr= this.homeService.getMyApps();
      }

       const options = {
            context: this.obsArr,
            fullscreen: true,
            viewContainerRef: this.vcRef
          };
          this.modal.showModal(FirstComponent, options).then((resource) => {
          });

FirstComponent.ts: (模式对话框)

  public firstAppArr: ObservableArray<App>;

    constructor(private params: ModalDialogParams, private routerExtensions: RouterExtensions) {
    }

    ngOnInit() {

        this.firstAppArr= this.params.context;
    }

first_component.html: (模式对话框html)

<RadListView [items]="firstAppArr" itemReorder="true">
    <ng-template let-item="item" let-i="index">
        <GridLayout rows="auto" columns="*,*">
            <StackLayout col="0" horizontalAlignment="left" verticalAlignment="center">
                <Label [text]="item.name" textWrap="true"></Label>
            </StackLayout>

            <StackLayout col="1" horizontalAlignment="right" verticalAlignment="center">
                <Label [text]="item.description" textWrap="true"></Label>

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

1 个答案:

答案 0 :(得分:0)

现在,您将firstAppArr设置为{"_observers":{}, "_array":[]}的对象,该对象不是您要查找的数组。我建议您将ngOnInit()更改为此

ngOnInit() {
    // if you are guaranteed context and array
    this.firstAppArr = this.params.context._array;

    // if you aren't guaranteed context or array. this will either be _array or undefined
    this.firstAppArr = this.params && this.params.context. && this.params.context._array;
}

访问对象的数组部分。