ReactJS 抛出 "map" is not defined 错误
ReactJS throws "map" is not defined Error
我对JavaScript不是很熟悉,但是我现在的项目必须在ReactJS中实现一个table。在下面的部分,我得到一个 error: map is not defined
。我做了一些错误研究,但无法在这里或 Google 上找到令人满意的答案。
render() {
const { hits } = this.props
return (
<div style={{width: '100%', boxSizing: 'border-box', padding: 8}}>
<table className="sk-table sk-table-striped" style={{width: '100%', boxSizing: 'border-box'}}>
<thead>
<tr>
<th>Title</th>
<th>Author</th>
<th>Keywords</th>
</tr>
</thead>
<tbody>
{map(hits, hit => (
<tr key={hit._id}>
<td>{hit._source.title}</td>
<td>{hit._source.year}</td>
<td>{hit._source.imdbRating}</td>
</tr>
))}
</tbody>
</table>
</div>
)
}
有人能给我指出正确的方向吗?
您必须在顶部创建的点击常量上使用地图功能。像这样:
{hits.map(hit => (
<tr key={hit._id}>
<td>{hit._source.title}</td>
<td>{hit._source.year}</td>
<td>{hit._source.imdbRating}</td>
</tr>
))}
map是javascript中Array原型上定义的函数。您在全局对象上调用 map ,它没有定义该方法。因此,你会得到一个未定义的错误。
hits.map 可能就是您要找的。
你的例子来自http://docs.searchkit.co/v2.0.0/components/basics/hits.html
在这种情况下,您需要声明地图...
放 :
import { map } from 'lodash'
在文件开头,在从 'searchkit'
导入 {....} 之后
我对JavaScript不是很熟悉,但是我现在的项目必须在ReactJS中实现一个table。在下面的部分,我得到一个 error: map is not defined
。我做了一些错误研究,但无法在这里或 Google 上找到令人满意的答案。
render() {
const { hits } = this.props
return (
<div style={{width: '100%', boxSizing: 'border-box', padding: 8}}>
<table className="sk-table sk-table-striped" style={{width: '100%', boxSizing: 'border-box'}}>
<thead>
<tr>
<th>Title</th>
<th>Author</th>
<th>Keywords</th>
</tr>
</thead>
<tbody>
{map(hits, hit => (
<tr key={hit._id}>
<td>{hit._source.title}</td>
<td>{hit._source.year}</td>
<td>{hit._source.imdbRating}</td>
</tr>
))}
</tbody>
</table>
</div>
)
}
有人能给我指出正确的方向吗?
您必须在顶部创建的点击常量上使用地图功能。像这样:
{hits.map(hit => (
<tr key={hit._id}>
<td>{hit._source.title}</td>
<td>{hit._source.year}</td>
<td>{hit._source.imdbRating}</td>
</tr>
))}
map是javascript中Array原型上定义的函数。您在全局对象上调用 map ,它没有定义该方法。因此,你会得到一个未定义的错误。
hits.map 可能就是您要找的。
你的例子来自http://docs.searchkit.co/v2.0.0/components/basics/hits.html
在这种情况下,您需要声明地图... 放 :
import { map } from 'lodash'
在文件开头,在从 'searchkit'
导入 {....} 之后