如何在更新特定表列时显示时间?

时间:2016-08-22 08:00:54

标签: reactjs

我希望在我的表格中最后更新latitudelongitude时显示时间。

我的代码目前显示上次更新的时间(通过网络 插座)。它没有显示时间latitudelongitude具体更新。我怎么解决这个问题? Here is a screen-shot of the table,代码如下:

componentDidMount() {
  let socket = new WebSocket('ws://139.162.2.53:9988');
  this.setState({ socket: socket });
  this.getSupportInfo();
  socket.onmessage = ((message) => {
    let socketData = JSON.parse(message.data);
    //console.log(socketData[0] );
    let device_id = socketData[0].device_id;
    let updatedSupportInfo = this.state.supportInfo;
    let now = new Date();
    let uSupport = updatedSupportInfo.map(function(item){
     if(device_id == item.device_id){
       // console.log(item);
       item.current_pos = socketData[0].current_pos;
       item["latlng"] = item.current_pos.x + ',' + item.current_pos.y;
       let time = new Date(socketData[0].timestamp)
       let a = moment(time);
       let b = moment(now);
       //let timeAgo = a.from(b);
       let timeAgo = b.diff(a, 'minutes')
       //console.log("a", a);
       //console.log("b", b);
       //console.log("timeAgo", timeAgo);
       item["timeAgo"] = timeAgo;
     }
     return item;
    });
    this.setState({supportInfo:uSupport})
  });
}

我正在使用反应引导表:

<TableHeaderColumn dataField="timeAgo" dataSort={true}>Time Ago(mins)</TableHeaderColumn>

0 个答案:

没有答案