일부 영화를 반환하는 Json 파일에 Ajax 요청을 만들고 있습니다. React 네이티브 상태가 변경되지 않습니다.
state = { movies: [] };
componentWillMount()
{
this.getMovies();
}
/*
Make an ajax call and put the results in the movies array
*/
getMovies()
{
axios.get('https://pastebin.com/raw/FF6Vec6B')
.then(response => this.setState({ movies: response.data }));
}
/*
Render every movie as a button
*/
renderMovies()
{
const { navigate } = this.props.navigation;
return this.state.movies.map(movie =>
<ListItem key={ movie.title }
title={ movie.title }
icon={{ name: 'home' }}
onPress={() =>
navigate('Details', { title: movie.title, release: movie.releaseYear })
}
/>
);
}
render() {
return(
<List>
{ this.renderMovies() }
</List>
);
}
내가 오류
은 다음과 같다 : this.state.map는 함수가 아닙니다. 이것은 영화가 여전히 비어 있기 때문입니다.내가 console.log response.data 일 때 JSON 파일에서 모든 행을 반환합니다. 문제는이 줄에서 가장 가능성이 높습니다.
.then(response => this.setState({ movies: response.data }));
누군가가 잘못된 것을 알고 있습니까?
확인이 https://stackoverflow.com/questions/47027035/why-is-my-react-component-this-state-updateclothing-saying-undefined-even-thou/47028520#47028520 –
바인딩 문제에 'getMovies' 함수 –
@Raiders 당신의 json 응답이 잘못된 형식입니다. 그것을 확인하시기 바랍니다. – jason