在映射对象上反应动态键

react dynamic key on mapping object

我需要通过动态键在映射中获取一个对象,它适用于字符串但不适用于映射的动态名称...

动态对象

data.map((item) => (

        console.log("** works with string:", props.programStructure["induction"]),

        console.log("** not working with dynamic:", props.programStructure[item.name])
    ))

Blockquote console.log("** not working with dynamic:", props.programStructure[[item.name]])

我认为是因为props.programStructure[[item.name]]

中多了[]

删除了多余的 []

var props  = {
  programStructure: {a: 1, b:2, induction: 'intro value'}
}

var data = [{name: 'a'}, {name: 'b'}]


data.map((item) => (

        console.log("** works with string:", props.programStructure["induction"]),

        console.log("** not working with dynamic:", props.programStructure[item.name])
    ))