Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.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 使用React语义UI中的服务器响应数据更新模式值_Reactjs_Modal Dialog_State_Semantic Ui_Prop - Fatal编程技术网

Reactjs 使用React语义UI中的服务器响应数据更新模式值

Reactjs 使用React语义UI中的服务器响应数据更新模式值,reactjs,modal-dialog,state,semantic-ui,prop,Reactjs,Modal Dialog,State,Semantic Ui,Prop,我有一个多个带有一些ID的超链接。单击链接时,我必须在模式中显示加载符号,并且我必须进行axios调用。一旦api返回数据,我就必须以相同的模式更新结果 下面是我的代码 class App extends React.Component { renderContent() { return ( // This data generated using map function <Modal trigger={<a onClick={() =

我有一个多个带有一些ID的超链接。单击链接时,我必须在模式中显示加载符号,并且我必须进行axios调用。一旦api返回数据,我就必须以相同的模式更新结果

下面是我的代码

class App extends React.Component {
   renderContent() {
     return (
       // This data generated using map function
       <Modal trigger={<a onClick={() => this.generateAppJson("1") }>Generate App JSON</a> } basic size='small'>
         <Header icon='spinner loading' content='Get the name' />
         <Modal.Content>
           <p>Loading...</p> {/* Here I have to update the content that received form  generateAppJson() function*/}
         </Modal.Content>
       </Modal>

       <Modal trigger={<a onClick={() => this.generateAppJson("2") }>Generate App JSON</a> } basic size='small'>
         <Header icon='spinner loading' content='Get the name' />
         <Modal.Content>
           <p>Loading...</p> {/* Here I have to update the content that received form  generateAppJson() function*/}
         </Modal.Content>
       </Modal>
     )
   }

  generateAppJson(id) {
    console.log(id)
    // Here I'll make axios call and I have to update the result in the same model
  }

  render() {
    return (
      <Segment>
        {this.renderContent()}
      </Segment>
    );
  }
}
类应用程序扩展了React.Component{
renderContent(){
返回(
//此数据是使用map函数生成的

您需要将axios返回数据保存到组件状态,该状态将自动重新启动您的应用程序

因此,首先需要在axios调用返回时更新组件状态:

  async generateAppJson(id) {
    const results = await axios.post(someurl, id);
    // this line will cause a rerender
    this.setState({results})
  }
然后需要初始化组件中的状态:

class App  extends React.Component {
   state = { results: [] }
然后需要检查渲染函数中的状态:

<Modal.Content>
    { !this.state.results.length && <p>Loading...</p>}
    { this.state.results.length &&
        this.state.results.map(result => <someothercomponent key={result} /> )
    }
</Modal.Content>

{!this.state.results.length&正在加载…

} {this.state.results.length&& this.state.results.map(result=>) }
您需要将axios返回数据保存到组件状态,该状态将自动重新启动您的应用程序

因此,首先需要在axios调用返回时更新组件状态:

  async generateAppJson(id) {
    const results = await axios.post(someurl, id);
    // this line will cause a rerender
    this.setState({results})
  }
然后需要初始化组件中的状态:

class App  extends React.Component {
   state = { results: [] }
然后需要检查渲染函数中的状态:

<Modal.Content>
    { !this.state.results.length && <p>Loading...</p>}
    { this.state.results.length &&
        this.state.results.map(result => <someothercomponent key={result} /> )
    }
</Modal.Content>

{!this.state.results.length&正在加载…

} {this.state.results.length&& this.state.results.map(result=>) }