我正在尝试从MDB数据库中获取数据以显示电影。最初,我实现了一个click事件来调用数据,但未发现任何错误。直到发生这种情况!
这是代码:
this.performSearch()
}
performSearch() {
console.log("Perform search using moviedb")
const urlString = "https://api.themoviedb.org/3/search/movie?query=avengers&api_key=1b5adf76a72a13bad99b8fc0c68cb085"
$.ajax({urlString,
success: (searchResults) => {
console.log("Fetched data successfully")
// console.log(searchResults)
const results = searchResults.results
var movieRows = []
results.forEach((movie) => {
console.log(movie.title)
});
const movie = <MovieRow movie={movie}/>
movieRows.push(movie)
this.setState({rows: movieRows})
答案 0 :(得分:0)
您没有结果。为了防止这种情况,您可以更改
const results = searchResults.results
到
const results = searchResults.results ? searchResults.results : []