将数组传递为prop

时间:2020-04-01 03:48:47

标签: reactjs components react-props

有人可以在这里解释我的错吗......

<Something
content={[
    {
        heading: "Add Company",
        icon: "plus",
        options: {[
            {
                image: "srcimage",
                text: "New Company",
                link: "test"
            }, {  //Errors here
                image: "srcimage",
                text: "Existing Company",
                link: "test"
            }
        ]}
    }, {
        heading: "Import Company",
        icon: "download",
        options: {[
            {
                image: "/src/image",
                text: "Class",
                link: "/test"
            },
            {
                image: "/src/image",
                text: "BGL",
                link: "/test"
            },
            {
                image: "/src/image",
                text: "SuperMate",
                link: "/test"
            }
        ]}
    }]
} />

我收到错误消息Unexpected token, expected "]",上面写着error here。最终,我想根据这样传递的内容来创建一些内容块...。

enter image description here

谢谢

2 个答案:

答案 0 :(得分:2)

@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); /* only needed once */ #tabbrowser-tabs .tabbrowser-tab .tab-close-button { display:none!important; } 是对象的无效语法。

{[]}

答案 1 :(得分:0)

对于options属性,您需要删除花括号,只需传递数组

options: [
  {
    image: "srcimage",
    text: "New Company",
    link: "test"
  }, 
  {
    image: "srcimage",
    text: "Existing Company",
    link: "test"
  }
]
相关问题