Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.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
Reactjs 使用hashes.map函数选择标记_Reactjs - Fatal编程技术网

Reactjs 使用hashes.map函数选择标记

Reactjs 使用hashes.map函数选择标记,reactjs,Reactjs,我有一个关于gethash的问题,有一个map函数,我想在标记中列出hash。列表项未定义。。。为什么? 我能得到一些帮助吗 import React, { Component } from 'react'; import axios from 'axios'; class Filter extends Component { constructor(props) { super(props); this.state =

我有一个关于gethash的问题,有一个map函数,我想在标记中列出hash。列表项未定义。。。为什么? 我能得到一些帮助吗

import React, { Component } from 'react';
import axios                from 'axios';

class Filter extends Component {
    constructor(props) {
        super(props);

        this.state = {
            hash: [
                "aSj1T", "CD6oL"
            ]
        }
    } 
    getHashes(){
        const hashes = this.state.hash;
        const listItems = hashes.map((hashes) => <option>{hashes}</option>);

        for (var i = 0; i < hashes.length; i++){       
            const hashUrl = "https://api/v1/hashes/" + hashes[i];

        axios.get(hashUrl)
            .then((response) => {
                const data = response.data[0];

                this.state.hash.push(data.hash);
            })

            .catch((error) => {
            console.log(error);
            }); 
        }
    }

    render() {
        return (
            <div>
              <select name="select" 
              type="select" value={this.getHashes}>
              {listItems}
              </select>
            </div>
           );
          }
export default Filter;
我精简了代码,它与reux axios和我的文本编辑器上更多。但是我希望你能在你的文本编辑器中运行这个来帮助我。它没有经过测试。如果你只是解释一下,它也很酷。

1-this.state.hash.pushdata.hash;不是一个好主意,你是变异的状态,而不是改变它的设置状态

2-listItems在函数getHashes中定义,但从未添加到状态或组件实例中,因此您无法在渲染函数中访问它


通过将select的值设置为函数,您试图实现的目标并不明显

为什么select的值是getHashes?getHashes是一个异步函数,而不是一个选择值。谢谢,我认为问题在于它没有定义,因为它不在您所说的渲染函数中。竖起大拇指!