Javascript React JS lodash get在同一个函数中
我想使用Lodash get在同一行中显示字符串的两个对象?或者可以使用chain(u.chain(vehicle).get('test').get('test2')) 这是示例JSON文件Javascript React JS lodash get在同一个函数中,javascript,reactjs,lodash,material-ui,Javascript,Reactjs,Lodash,Material Ui,我想使用Lodash get在同一行中显示字符串的两个对象?或者可以使用chain(u.chain(vehicle).get('test').get('test2')) 这是示例JSON文件 { "results": [ { "vehicle": { "plate_no": "ABC 1234", "model": "Toyota Innova" } }
{
"results": [
{
"vehicle": {
"plate_no": "ABC 1234",
"model": "Toyota Innova"
}
}
]
}
我使用的是MaterialUI卡,我的代码如下所示
{_.map(this.state.vehicle, (d, idx) =>{
return(
<Col xs={6} style={{margin: '20px 0 5px' }}>
<Card key={d.id}>
<CardHeader
avatar="http://lorempixel.com/100/100/nature/"
title={_.get(d.vehicle, 'model') - _.get(d.vehicle, 'plate_no')}
actAsExpander={true}
showExpandableButton={true}
style={{backgroundColor: Colors.grey200}}
/>
{{.map(this.state.vehicle,(d,idx)=>{
返回(
我的目标是显示标题,如下所示
{_.map(this.state.vehicle, (d, idx) =>{
return(
<Col xs={6} style={{margin: '20px 0 5px' }}>
<Card key={d.id}>
<CardHeader
avatar="http://lorempixel.com/100/100/nature/"
title={_.get(d.vehicle, 'model') - _.get(d.vehicle, 'plate_no')}
actAsExpander={true}
showExpandableButton={true}
style={{backgroundColor: Colors.grey200}}
/>
Toyota Innova-ABC 1234您可以按所需的顺序使用所需的属性数组,然后数组#加入它们:
const d={
“车辆”:{
“车牌号”:“ABC 1234”,
“型号”:“丰田Innova”
}
};
const result=u.at(d.vehicle,['model','plate_no'])。连接('-');
console.log(结果);
Thank man:)它可以工作,但不知怎么回事?你不能使用两个lodash函数?你可以像在模板字符串中一样使用两个lodash函数-.get()
。${{.get(d.vehicle,'model')}-${.get(d.vehicle,'plate'no')}。谢谢你的帮助:)