Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 反应抛出;“地图”;未定义错误_Javascript_Reactjs_Mapping_Searchkit - Fatal编程技术网

Javascript 反应抛出;“地图”;未定义错误

Javascript 反应抛出;“地图”;未定义错误,javascript,reactjs,mapping,searchkit,Javascript,Reactjs,Mapping,Searchkit,我不太熟悉JavaScript,但必须为我当前的项目在ReactJS中实现一个表。在下面的部分,我得到一个错误:映射未定义。我做了一些错误研究,但在这里或谷歌上找不到令人满意的答案 render() { const { hits } = this.props return ( <div style={{width: '100%', boxSizing: 'border-box', padding: 8}}>

我不太熟悉JavaScript,但必须为我当前的项目在ReactJS中实现一个表。在下面的部分,我得到一个
错误:映射未定义
。我做了一些错误研究,但在这里或谷歌上找不到令人满意的答案

   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>
        )
    }
render(){
const{hits}=this.props
返回(
标题
作者
关键词
{map(点击,点击=>(
{hit._source.title}
{hit._source.year}
{hit._source.imdbRating}
))}
)
}

有人能给我指出正确的方向吗?

您必须在顶部创建的点击量上使用map函数。像这样:

{hits.map(hit => (
  <tr key={hit._id}>
    <td>{hit._source.title}</td>
    <td>{hit._source.year}</td>
    <td>{hit._source.imdbRating}</td>
  </tr>
))}
{hits.map(hit=>(
{hit._source.title}
{hit._source.year}
{hit._source.imdbRating}
))}

您必须在顶部创建的hits const上使用map函数。像这样:

{hits.map(hit => (
  <tr key={hit._id}>
    <td>{hit._source.title}</td>
    <td>{hit._source.year}</td>
    <td>{hit._source.imdbRating}</td>
  </tr>
))}
{hits.map(hit=>(
{hit._source.title}
{hit._source.year}
{hit._source.imdbRating}
))}

map是在javascript中的数组原型上定义的函数。您正在全局对象上调用map,该对象没有定义该方法。因此,您会得到一个未定义的错误


hits.map可能就是您想要的。

map是在javascript中的数组原型上定义的函数。您正在全局对象上调用map,该对象没有定义该方法。因此,您会得到一个未定义的错误

hits.map可能就是您正在寻找的内容。

是您的示例

在这种情况下,您需要声明映射。。。 付诸表决:

在文件开始时,从“searchkit”导入{….}后,

是您的示例

在这种情况下,您需要声明映射。。。 付诸表决:


在文件开始时,从“searchkit”

导入{…}后,是一个数组方法,因此您希望在数组中调用它,并给出一个函数作为参数,该函数应为数组中的每个元素执行<代码>点击.map(点击=>…)
非常感谢!数组方法立即得到了帮助,因此您希望在数组中调用它,并提供一个函数作为参数,该函数应针对数组中的每个元素执行<代码>点击.map(点击=>…)
非常感谢!立即帮助