Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/412.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 异步按钮处理程序函数中的setState值在渲染中不为空_Javascript_Reactjs - Fatal编程技术网

Javascript 异步按钮处理程序函数中的setState值在渲染中不为空

Javascript 异步按钮处理程序函数中的setState值在渲染中不为空,javascript,reactjs,Javascript,Reactjs,我正在尝试设置asyn buttonHander函数中的值。它在onSortedViewHandler函数中工作正常,但当我尝试在render array中console.log数组值为空时,我不知道为什么,但它没有渲染 state={inputText:,sortedArrayList:[]} onSortedViewHandler = async () => { const data = await this.props.sortedContract.methods

我正在尝试设置asyn buttonHander函数中的值。它在onSortedViewHandler函数中工作正常,但当我尝试在render array中console.log数组值为空时,我不知道为什么,但它没有渲染

state={inputText:,sortedArrayList:[]}

  onSortedViewHandler = async () => {
    const data = await this.props.sortedContract.methods
      .sortNumberArrayList()
      .call()
      .then((array) => {});

    this.setState({ sortNumberArrayList: data });       // array output is correct here
    console.log(data);
    console.log(this.state.sortNumberArrayList);       // array output is correct here
  };
它在这个功能中运行良好

但不是数组在渲染中显示为空

render() {
console.log(this.state.sortedArrayList);        //but empty here
}
``

这将使您得到正确的答案。您有不同的命名状态。

状态属性有不同的名称:
sortNumberArrayList
SortDarrayList
哦,我的错,非常感谢@DanielCheung
render() {
 console.log(this.state.sortNumberArrayList);       
}