【发布时间】:2018-12-23 19:50:18
【问题描述】:
假设返回组件通过获取字符串数组来实现下拉列表。使用数组元素的方式可能有些错误。
import React from 'react'
class DropDownList extends React.Component {
renderDropDownList = () => {
const { dropDownDownData } = this.props
return (
<div className="book-shelf-changer">
<select>
dropDownDownData.map(function(item){
<option key = {item} value={item}>{item}</option>
})
</select>
</div>
)
}
render() {
const optionList = ['Move to...','Currently Reading','Want to Read','Read','None']
return this.renderDropDownList(optionList)
}
}
export { DropDownList }
【问题讨论】:
-
尝试返回整个
option元素-> 只需在<option key={item}...前面添加return。还可以尝试console.log(dropDownDownData)来查看该变量是否实际上是一个字符串数组,或者您期望的任何内容 -
为什么你把这个常量写在花括号里?
-
@antdav 这是解构赋值?
-
这充满了错别字。 1)您忘记了内联 JS 表达式的地图周围的花括号。 2)您需要从地图回调中返回
标签: javascript reactjs