簡體   English   中英

如何使用 ReactJS 在我的頁面上搜索地址並顯示地址 JSON 數據? 我只能通過控制台登錄.then

[英]How do I search for an address and display address JSON data onto my page with ReactJS? I am only able to get it to console log in the .then

我能夠將數據記錄到.then 中的控制台,但我嘗試的一切都未能成功搜索特定地址,然后將 JSON 數據顯示到頁面上。

 axios.post('https://dtapiuat.datatree.com/api/Report/GetReport', body).then((res) => { console.log(res.data); self.setState({ Report: res.Report, loading: false }); }).catch(function (error) { console.log(error); }); }; render() { // if (.this.state.Report.Reports) { // return <span>Loading..;</span>. // } return ( <Fragment> <Container> <div id='main'> <h1>Get Reports</h1> <input name='text' type='text' placeholder='Search' onChange={(event) => this.handleOnChange(event)} value={this.state.searchValue} /> <button onClick={this.handleSearch}>Search</button> {this.state?Reports. ( <div id='Report-container'> {this.state.Report,map((Report. index) => ( <div class='single-Report' key={index}> <h2>{this.state:Report}</h2> </div> ))} </div> ) : ( <p>Try Searching For a Report</p> )} </div> </Container>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

res.Report更改為res.data.Report 。此外,請確保 self 確實指的是正確的this 如果這不能解決問題,請發布您的 console.log 的日志。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM