우선, 내가하고 싶은 일과 문제가있는 부분을 설명하고 싶습니다.렌더링 할 여러 함수 호출
처음에는 일부 데이터를로드하기 위해 페치 요청을 수행합니다. 여기서는 작동 중이기 때문입니다. 이 데이터의 한 값으로 다른 페치를 수행하고 싶습니다. 이를 위해 다른 함수를 호출합니다. renderImage(), 여기서 가져 오기를 수행하고 원하는 코드를 렌더링합니다.
내 상태는로드 된 상태로 변경되지 않으므로 아무것도 렌더링하지 않습니다. 그리고 물론 가져 오기는 비동기 적이며 더 많은 시간이 필요합니다. 그리고 나는 그것이 조금 복잡하다고 생각하기 때문에 그것이 어떻게 작동하고 더 단순한지를 모른다.
이
내 코드입니다 :class Dashboard extends Component{
constructor(props){
super(props)
this.state = {
dataSource: new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 !== row2
}),
loaded: false,
datos: '',
}
}
componentDidMount(){
this.fetchData();
}
fetchData(){
fetch(REQUEST_URL)
.then((response) => response.json())
.then ((responseData) =>{
this.setState({
dataSource: this.state.dataSource.cloneWithRows(responseData),
})
})
}
renderLoadingView(){
return(
<View>
<Text>Cargando...</Text>
</View>
)
}
async renderImage(receta){
const REQUEST_URL = "yyyyyyyy" + receta.user_id;
const response = await fetch(REQUEST_URL);
const json = await response.json();
this.setState({ loaded : true});
return(
<Card >
<CardItem>
<Left>
<TouchableOpacity>
<Thumbnail style={{width: 50, height: 50, borderRadius: 25}} source={{uri: json.imageUrl}} />
</TouchableOpacity>
<Body>
<Text>{receta.Titulo}</Text>
<Text>{receta.Username}</Text>
</Body>
</Left>
</CardItem>
</Card>
)
}
renderReceta(receta){
return this.renderImage(receta);
}
render(){
if(!this.state.loaded){
return this.renderLoadingView();
}
else{
return(
<Container>
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderReceta.bind(this)}
/>
</Container>
)
}
}
}
당신이'renderReceta'와'renderImage' 그리고 당신이 달리는 다른 함수를 반환 할 필요가 있습니다 – bennygenel
@bennygenel 감사합니다! 나는 그것을 바꿨지 만 여전히 작동하지 않습니다. 이제 루프를 입력하고 아무 것도 반환하지 않습니다. – dddddrrrrrr
목록 항목을 렌더링하는 동안 상태를 설정하는 중입니다. 그러면 다시 렌더링되고 다른 상태 설정이 트리거되어 다시 렌더링됩니다. – bennygenel