简体   繁体   English

将两个返回语句合二为一

[英]combine two return statements into one

i have the following code:我有以下代码:

 const Test = obj && obj.length > 0 && obj.map((myguids2, key) => {
    const url2 = myguids2.predicatList.map(mypredicats => {
        const url = mypredicats.p
        var arr = url.split('/')[3]
        return ( 
                            <div>{arr}</div>
                )
    })
    const content = myguids2.guidList.map((myqueriedguids, key) => {
        return (
            <tr>
                 <td>{myqueriedguids.guid.includes('http://linkedbuildingdata.net/ifc/resources20201208_005325/') ? <MyPopUp myproperties={guidList} myguidnames={myqueriedguids.guid}>{myqueriedguids.guid}</MyPopUp> : myqueriedguids.guid}</td>
            </tr>
            )
    })
    return content

})

i want to combine the output from url2 with the output coming from content into a two column table with url2 in the left table column and content in the right table我想将来自 url2 的 output 与来自内容的 output 组合成一个两列表,其中 url2 在左表列中,内容在右表中

is there way to structure the function in such a way?有没有办法以这种方式构造 function?

Just return an object只需返回 object

const Test = obj && obj.length > 0 && obj.map((myguids2, key) => {
        const url2 = myguids2.predicatList.map(mypredicats => {
            const url = mypredicats.p
            var arr = url.split('/')[3]
            return ( 
                                <div>{arr}</div>
                    )
        })
        const content = myguids2.guidList.map((myqueriedguids, key) => {
            return (
                <tr>
                     <td>{myqueriedguids.guid.includes('http://linkedbuildingdata.net/ifc/resources20201208_005325/') ? <MyPopUp myproperties={guidList} myguidnames={myqueriedguids.guid}>{myqueriedguids.guid}</MyPopUp> : myqueriedguids.guid}</td>
                </tr>
                )
        })
        return { content, url2  }
    
    })

Then you can access properties by然后您可以通过以下方式访问属性

Test.content or Test.url2 Test.contentTest.url2

So the best way for now is to split the Const Test into two variables one containing the url2 and one the content.因此,目前最好的方法是将 Const Test 拆分为两个变量,一个包含 url2,一个包含内容。 using a return statement i managed to put {url2}: {Test} to gain the two column output使用返回语句我设法把 {url2}: {Test} 获得两列 output

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM