Arrays 使用';参考';在React中作为数组
当我试图在React with Redux中将输入引用为数组时,我遇到了一些问题 下面的代码映射数组中每个项目的一个面板Arrays 使用';参考';在React中作为数组,arrays,reactjs,ref,Arrays,Reactjs,Ref,当我试图在React with Redux中将输入引用为数组时,我遇到了一些问题 下面的代码映射数组中每个项目的一个面板 var articles = this.props.item.array.articles.map((article, index) => { return <Panel key={index} header={'Article ' + index}> <Input type='select' ref='id' label='
var articles = this.props.item.array.articles.map((article, index) => {
return <Panel key={index} header={'Article ' + index}>
<Input type='select' ref='id' label='Article' defaultValue={article.id} >
{articles}
</Input>
</Panel>
})
价格和数量指数将增加2项投入
我决定不在代码示例中包含它
非常感谢为这个问题提供一个很好的解决方案。我相信您可以使用
对象.keys
像数组一样迭代这个.refs
例如,Object.keys(this.refs).forEach(key=>func(this.refs[key]))
为每个引用运行
func
函数。问题不清楚this.refs
是一个String
键控的对象
,不是一个“JSON数组”不,不是,我的意思是我想要的文章索引输出是一个指定格式的JSON数组。这个数组与refs
有什么关系?可以很简单:Object.values(this.refs)
"articles": [
{
"_joinData": {
"price": "100",
"quantity": "50"
},
"id": "05f54207-fb6f-40b5-820e-26059a803343"
},
{
"_joinData": {
"price": "200",
"quantity": "70"
},
"id": "05f54207-fb6f-40b5-820e-26059a803343"
}
]