我希望在我的表格中最后更新latitude
和longitude
时显示时间。
我的代码目前显示上次更新的时间(通过网络
插座)。它没有显示时间latitude
或longitude
具体更新。我怎么解决这个问题? 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>