gpt4 book ai didi

javascript - 用对象 react Native FlatList

转载 作者:行者123 更新时间:2023-12-03 19:43:37 26 4
gpt4 key购买 nike

我想用 React Native 的 FlatiList 渲染对象,但是这个组件没有返回预期的结果。
我的字典是这样的:

Object {
"Lisa.Sky": Object {
"name": "Lisa",
"surname": "Sky",
"age": 21,
"sex": female
},
"Thomas.Prat": Object {
"name": "Thomas",
"surname": "Prat",
"age": 33,
"sex": male
},
"Paul.Sing": Object {
"name": "Paul",
"surname": "Sing",
"age": 88,
"sex": male
},
"Andrew.Brown": Object {
"name": "Andrew",
"surname": "Brown",
"age": 23,
"sex": male
},
}

我已经实现了这样的 FlatList,但是我有白屏
   <View>
<ScrollView>
<FlatList
data={this.props.nameList}
renderItem={({item}) =>
<View key={item.name + "." + item.surname}>
<Text style={styles.viewDetail}>{item.name}</Text>
<Text style={styles.viewDetail}>{item.surname}</Text>
<Text style={styles.viewDetail}>{item.age}</Text>
<Text style={styles.viewDetail}>{item.sex}</Text>
</View>
}
keyExtractor={(index) => index.toString()}
/>
</ScrollView>
</View>

谢谢

最佳答案

你可以这样做。
检查工作零食。 https://snack.expo.io/@nazrdogan/bad-cashew

import * as React from 'react';
import { Text, View, StyleSheet, FlatList } from 'react-native';
import { Constants } from 'expo';

// You can import from local files
import AssetExample from './components/AssetExample';

// or any pure javascript modules available in npm
import { Card } from 'react-native-paper';
var obj = {
'Lisa.Sky': {
name: 'Lisa',
surname: 'Sky',
age: 21,
sex: 'female',
},
'Thomas.Prat': {
name: 'Thomas',
surname: 'Prat',
age: 33,
sex: 'male',
},
'Paul.Sing': {
name: 'Paul',
surname: 'Sing',
age: 88,
sex: 'male',
},
'Andrew.Brown': {
name: 'Andrew',
surname: 'Brown',
age: 23,
sex: 'male',
},
};
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<FlatList
data={Object.keys(obj)}
renderItem={({ item }) => <Text>{obj[item].name}</Text>}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
padding: 8,
},
});

关于javascript - 用对象 react Native FlatList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54143317/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com