【发布时间】:2019-10-29 06:15:27
【问题描述】:
如何放置数组的第一行
"id":"1","name":"Some Name","bal":"1000"
在<Text>{name} {balance}</Text>
然后是<FlatList /> 中的其他 2 行。我可以通过获取数组来显示 FlatList 或 Text,但不能同时显示两者。如果我让另一个屏幕放入第一行然后将其导入第二个屏幕,我就能够显示所需的结果。但是我认为有更好的方法可以将这个数组划分为单个屏幕并显示Text和FlatList。谢谢。
[
[
{
"id": "1",
"name": "Some Name",
"bal": "1000",
"ab": "1000"
}
],
{
"area": "North",
"building": "Some Building",
"unit_number": "123"
},
{
"area": "North",
"building": "Some Building",
"unit_number": "123"
}
]
更新:请查看代码。我已经注释掉了我需要在
中提取和显示数组的第一行的行export default class ClientDetails extends Component {
constructor() {
super()
this.state = {
isLoading: true
}
}
renderItem = ({ item }) => {
return (
<View>
<Text>
{item.area}
</Text>
<Text>
Rent Amount: {item.building}
</Text>
<Text>
Rent Amount: {item.unit_number}
</Text>
</View>
)
}
componentDidMount = () => {
return fetch("http://192.168.0.106/db_1/list.php?id=1")
.then((response) => response.json())
.then((responseJson) => {
this.setState({
isLoading: false,
dataSource: responseJson,
})
})
}
render() {
return (
<View style={styles.MainContainer}>
//Here I was to put <Text> {id}{name}{bal}</Text> but I can either get <Text> to display or <FlatList>
<FlatList
data={ this.state.dataSource }
ItemSeparatorComponent = {this.renderSeparator}
renderItem={this.renderItem}
keyExtractor={(item, index) => index.toString()}
/>
</View>
);
}
}
【问题讨论】:
-
我无法理解您的意图,您能否描述清楚并提供示例图片
-
你在问题中写的数组无效?
-
正如@VigneshVPai 所说,您的数组形状不合适。
-
@in.k,但我可以让
显示或 ,这是什么意思?
标签: arrays react-native react-native-flatlist