代码之家  ›  专栏  ›  技术社区  ›  F. Ception

物料数据表未显示更新数据

  •  0
  • F. Ception  · 技术社区  · 6 年前

    输入数据更改时,我的物料数据表不显示/更新。只有当我从按钮调用刷新函数时。在ngOnChanges中,刷新也不起作用。 除了通过按钮调用refresh函数之外,如何更新表的视图?

    export interface VariableObject {
      name: string;
      node: string;
      status: string;
      subscriber: any;
      type: string;
      value: any;
    }
    

    组成部分

    @Input() data: VariableObject[];
    displayedColumns: string[] = ['name', 'type', 'status', 'value'];
    dataSource = new MatTableDataSource<VariableObject>();
    
    ngOnChanges(changes: SimpleChanges): void {
      this.dataSource = new MatTableDataSource<VariableObject>(this.data); }
    
    refresh() {
      this.dataSource = new MatTableDataSource<VariableObject>(this.data); }
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Alonso Dominguez    6 年前

    据我所知,角度无法识别物体是否发生了变化。它只能监听变量和(可能)对象属性的更改。

    也许你可以监听一个不同的变量,在数据更改时触发事件

    以下是解决方法:

    this.ObjectName = Object.assign({}, this.ObjectName);

    这样角度就能探测到变化并开火 ngOnChanges . 必须在父组件中重新分配对象。