【发布时间】:2019-06-06 23:34:17
【问题描述】:
在我的项目中,我从服务器获取json 数据并在card 中列出。但我面临的问题是,每当将新项目添加到json data 时,新项目将呈现在底部现有的card。但我想要的是它应该填充在现有cards的顶部。那我该怎么做?以下是我获取和列出卡片的示例代码。请帮我找到解决方案.任何帮助都会非常感激。谢谢。
componentWillMount(){
fetch(GLOBAL.NEW_WORK_REQUEST,{
method: 'POST',
headers:{
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body:JSON.stringify({
name:"name"
})
})
.then((response) => response.json())
.then((responseData) =>
{
this.setState({
work_rq :responseData.data
})
});
}
}
...
...
<View>
{this.state.work_rq.map(a => (
<CardSection>
<TouchableOpacity>
<Text style={{fontSize:18,padding:8}}>Work Category:{a.work_type}</Text>
</TouchableOpacity>
</CardSection>
))}
</View>
【问题讨论】:
标签: javascript json react-native fetch jsx