繁体   English   中英

如何迭代对象数组并更新时间,如果<mat-checkbox>在 angular 9 中检查?</mat-checkbox>

[英]How to iterate over array of objects and update time if <mat-checkbox> is checked in angular 9?

我的<mat-table>中有一组对象,同步属性是<mat-checkbox> 我正在尝试这样做,以便在选中一个框然后按下“同步”按钮时,它将使用表中的当前日期和时间更新 lastSynced 属性。

    export interface ConnectionData {
  name: string;
  active: boolean;
  connections: string;
  location: string;
  users: string;
  sync: boolean;
  lastSynced: Date | null;

} 

const CONNECTIONS: ConnectionData[] = [
  {name: '', active: false, connections: '', location: '', users: '', sync: false, lastSynced: },
  {name: '', active: false, connections: '', location: '', users: '', sync: false, lastSynced: },{name: '', active: false, connections: '', location: '', users: '', sync: false, lastSynced: },

];

拥有在更新表数据的同步按钮(单击)上调用的方法。 就像是:

for( const connection of connectionData ) {
    if(connection.sync) {
       connection.lastSynced = new Date(); // update to current date
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM