将数组数组作为道具传递

Passing array of arrays as 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。最后我想根据这样传入的内容创建一些内容块....

谢谢

{[]} 不是对象的有效语法。

content={[
  {
    heading: "Add Company",
    icon: "plus",
    options: [ // remove the curly boy that was here
      {
        image: "srcimage",
        text: "New Company",
        link: "test"
      }, { 
        image: "srcimage",
        text: "Existing Company",
        link: "test"
      }
    ] // and here
  }, {
    heading: "Import Company",
    icon: "download",
    options: [ // and here
      {
        image: "/src/image",
        text: "Class",
        link: "/test"
      },
      {
        image: "/src/image",
        text: "BGL",
        link: "/test"
      },
      {
        image: "/src/image",
        text: "SuperMate",
        link: "/test"
      }
    ] // and here
  }]}

需要去掉大括号的options属性,传入数组即可

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