Javascript 在ReactJs中连接多个数组映射
我是reactjs中的新手,在reactjs中也可以这样做,比如mysql内部连接,这里是我的示例代码Javascript 在ReactJs中连接多个数组映射,javascript,reactjs,array-map,Javascript,Reactjs,Array Map,我是reactjs中的新手,在reactjs中也可以这样做,比如mysql内部连接,这里是我的示例代码 {dataCustomer.map((customer) => ( <tr> <td>{customer.custid}</td> <td>{customer.custname}</td> <td
{dataCustomer.map((customer) => (
<tr>
<td>{customer.custid}</td>
<td>{customer.custname}</td>
<td>{customer.mailingaddr}</td>
<td>{customer.stateid}</td>
<td>{customer.districtid}</td>
<td>{customer.postcode}</td>
</tr>
))}
{dataState.map((state) => (
<tr>
<td>{state.stateid}</td>
<td>{state.statename}</td>
</tr>
))}
{dataCustomer.map((客户)=>(
{customer.custid}
{customer.custname}
{customer.mailingaddr}
{customer.stateid}
{customer.districtid}
{客户.邮政编码}
))}
{dataState.map((state)=>(
{state.stateid}
{state.statename}
))}
如何在不使用SQL语法的情况下将customer.stateid和state.stateid中的数组映射数据连接到state.statename?。这可能吗?这不完全相同,但我认为我编写的以下函数可以帮助您:
让客户=[{
姓名:"富",,
国家编号:1
},
{
姓名:“Boo”,
国家编号:3
},
{
姓名:“咕”,
国家编号:2
},
{
名称:“动物园”,
国家编号:2
},
];
让状态=[{
名称:“州1”,
身份证号码:1
},
{
名称:“State2”,
身份证号码:2
},
];
函数联接(客户、状态、第1列、第2列){
返回customers.map(customer=>{
states.forEach(state=>{
if(客户[column1]==状态[column2]){
客户[“状态”]={…状态};
}
})
退货客户;
})
}
log(join(客户、状态、“stateid”、“id”))
这应该有效
let joinedData=[]
dataCustomer.forEach((customer)=>{
let st= dataState.filter((state)=>state.stateid===customer.stateid);
if(st.length>0)
joinedData.push({...customer,statename:st[0].statename})
})
joinedData数组现在将包含具有相应statename的customer对象,您可以将其用作
{joinedData.map((customer) => (
<tr>
<td>{customer.custid}</td>
<td>{customer.custname}</td>
<td>{customer.mailingaddr}</td>
<td>{customer.stateid}</td>
<td>{customer.districtid}</td>
<td>{customer.postcode}</td>
<td>{customer.statename}</td>
</tr>
))}
{joinedData.map((客户)=>(
{customer.custid}
{customer.custname}
{customer.mailingaddr}
{customer.stateid}
{customer.districtid}
{客户.邮政编码}
{customer.statename}
))}
谢谢,很好。