看不到我从谷歌距离API获得的数据的映射结果。
import React, { Component } from 'react';
import { connect } from 'react-redux';
import SearchComponent from './search_component';
import _ from 'lodash';
class App extends Component {
constructor(props) {
super(props);
this.state = {
distances: ''
}
}
componentWillReceiveProps(newProps) {
if(newProps.Distances) {
this.setState({
distances: newProps.Distances
})
}
}
renderDistancesList() {
if(_.isObject(this.state.distances)){
let d = this.state.distances;
console.log('this.state.distances ', d);
return (
<div>
<h4>Distsances:</h4>
{
_.map(d, (key, value) => {
return <li key={key}>{key}</li>
})
}
</div>
)
} else {
return (<div>Loading data...</div>)
}
}
render() {
return (
<div>
<div>HelloFrom App</div>
<SearchComponent/>
{this.renderDistancesList()}
</div>
)
}
}
function mapStateToProps({ Distances }) {
return { Distances }
}
export default connect(mapStateToProps, null)(App);
答案 0 :(得分:0)
我通常使用es6中的map函数而不是来自lodash或其他东西 但实际上我会做什么
select tAsset.*,latitudeLongitude.latitude,
latitudeLongitude.longititue
from t_assettAsset inner join latitudeLongitude
on t_assettAsset.id = latitudeLongitude.asset_id