在本机反应中如何将获取响应数组对象附加到渲染函数中?
In react native how to append fetch response array object in to render function?
我需要将下面的数组数据显示到渲染函数中:
我会知道如何循环数据并在 Render 中显示它。
[{
profileid: 1,
enabled: 1,
attachment: '',
id: 233,
topicid: 47,
tstamp: 'January, 21 2016 15:06:31 +1100',
body: 'to check orders'
}, {
profileid: 2,
enabled: 1,
attachment: '',
id: 233,
topicid: 47,
tstamp: 'January, 21 2016 15:06:31 +1100',
body: 'to check orders'
} ]
这是一个例子。
import React from 'react'
import { View, Text } from 'react-native'
...
const data = [{
profileid: 1,
enabled: 1,
attachment: '',
id: 233,
topicid: 47,
tstamp: 'January, 21 2016 15:06:31 +1100',
body: 'to check orders'
}, {
profileid: 2,
enabled: 1,
attachment: '',
id: 233,
topicid: 47,
tstamp: 'January, 21 2016 15:06:31 +1100',
body: 'to check orders'
} ]
...
render() {
return (
<View>
{data.map((dataItem) =>
<View key={dataItem.profileid}>
<Text>{dataItem.profileId}</Text>
<Text>{dataItem.enabled}</Text>
<Text>{dataItem.attachment}</Text>
<Text>{dataItem.id}</Text>
<Text>{dataItem.topicid}</Text>
<Text>{dataItem.tstamp}</Text>
<Text>{dataItem.body}</Text>
</View>
)}
</View>
)
}
希望对你有帮助
class Parent extends React.Component{
constructor(props){
super(props);
this.state = {
gists : []
}
}
componentDidMount() {
fetch('http://rest.......')
.then(response => response.json())
.then(gists => this.setState({ gists }))
}
render(){
return (
<ul>
{this.state.gists.map(gist => (
<li key={gist.countryId}>{gist.name}</li>
))}
</ul>
)
}
}
Parent.propTypes = {
data: React.PropTypes.array
}
我需要将下面的数组数据显示到渲染函数中:
我会知道如何循环数据并在 Render 中显示它。
[{
profileid: 1,
enabled: 1,
attachment: '',
id: 233,
topicid: 47,
tstamp: 'January, 21 2016 15:06:31 +1100',
body: 'to check orders'
}, {
profileid: 2,
enabled: 1,
attachment: '',
id: 233,
topicid: 47,
tstamp: 'January, 21 2016 15:06:31 +1100',
body: 'to check orders'
} ]
这是一个例子。
import React from 'react'
import { View, Text } from 'react-native'
...
const data = [{
profileid: 1,
enabled: 1,
attachment: '',
id: 233,
topicid: 47,
tstamp: 'January, 21 2016 15:06:31 +1100',
body: 'to check orders'
}, {
profileid: 2,
enabled: 1,
attachment: '',
id: 233,
topicid: 47,
tstamp: 'January, 21 2016 15:06:31 +1100',
body: 'to check orders'
} ]
...
render() {
return (
<View>
{data.map((dataItem) =>
<View key={dataItem.profileid}>
<Text>{dataItem.profileId}</Text>
<Text>{dataItem.enabled}</Text>
<Text>{dataItem.attachment}</Text>
<Text>{dataItem.id}</Text>
<Text>{dataItem.topicid}</Text>
<Text>{dataItem.tstamp}</Text>
<Text>{dataItem.body}</Text>
</View>
)}
</View>
)
}
希望对你有帮助
class Parent extends React.Component{
constructor(props){
super(props);
this.state = {
gists : []
}
}
componentDidMount() {
fetch('http://rest.......')
.then(response => response.json())
.then(gists => this.setState({ gists }))
}
render(){
return (
<ul>
{this.state.gists.map(gist => (
<li key={gist.countryId}>{gist.name}</li>
))}
</ul>
)
}
}
Parent.propTypes = {
data: React.PropTypes.array
}