代码之家  ›  专栏  ›  技术社区  ›  Stephen Alejandro Alcalde

将ObservableArray传递到Model对话框参数,显示RadListView数据具有[object object]

  •  0
  • Stephen Alejandro Alcalde  · 技术社区  · 7 年前

    我已将可观察数组传递给模态对话框参数。打开模式对话框时,我从radlistview has[object object]中得到一个值。

    但如果我用ListView它的工作正常。只有用RadListView我才能解决这个问题。

    家庭组件.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) => {
              });
    

    第一组件.ts: (模式对话框)

      public firstAppArr: ObservableArray<App>;
    
        constructor(private params: ModalDialogParams, private routerExtensions: RouterExtensions) {
        }
    
        ngOnInit() {
    
            this.firstAppArr= this.params.context;
        }
    

    第一个组件.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 回复  |  直到 7 年前
        1
  •  0
  •   rhavelka    7 年前

    现在你正在设置 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;
    }
    

    访问对象的数组部分。

    推荐文章