【发布时间】:2022-01-04 19:56:19
【问题描述】:
我写了这段代码:
<View style={styles.container}>
<FlatList
data={data}
style={styles.menu}
renderItem={({item, index})=>
<TouchableOpacity>
<View style={styles.menuItem}>
<Text style={item.active ? styles.menuItemTextActive : {}}>{item.title}</Text>
</View>
</TouchableOpacity>
}
showsHorizontalScrollIndicator={false}
horizontal
/>
</View>
const styles = StyleSheet.create({
container: {
flex: 1,
},
menu:{
width: "100%",
paddingVertical: 5,
flexGrow: 0,
},
menuItem:{
paddingHorizontal: 10,
paddingVertical: 5,
borderWidth: 1,
borderColor: '#CCC',
borderRadius: 10,
marginHorizontal: 3,
},
});
我还重置了 NodeJS 服务器缓存,但问题仍未解决。第一次写没问题,不知道怎么一下子就出现了这个问题
这是我的数据如果有帮助:
const [data, setData] = useState([
{
title: 'پرفروشترینها',
order: '`buy` DESC',
active: true
},
{
title: 'پرسودترینها',
order: '(`price` - `primary_price`) DESC',
where: '`primary_price` > 0'
},
{
title: 'کمفروشترینها',
order: '`buy` ASC',
},
{
title: 'کمترین موجودی',
order: '`qty`',
where: '`qty` > -1'
},
{
title: 'کمسودترینها',
order: '(`price` - `primary_price`) ASC',
where: '`primary_price` > 0'
},
{
title: 'بیشترین موجودی',
order: '`qty` DESC',
where: "`qty` > -1 AND `qty` != ''"
},
{
title: 'پرسودترین فاکتورها',
order: '`profit` DESC',
where: '`profit` > 0',
type: 'invoice'
},
{
title: 'پرتعدادترین فاکتورها',
order: '`count` DESC',
type: 'invoice'
},
{
title: 'گرانترینها',
order: '`price` DESC',
},
{
title: 'ارزانترینها',
order: '`price` ASC',
},
{
title: 'بدوننامها',
where: "`name` = ''",
},
{
title: 'بدونموجودیها',
order: '`qty` DESC',
where: "`qty` < 1",
},
{
title: 'بدونقیمتخریدها',
where: "`primary_price` < 1",
},
]);
【问题讨论】:
-
我运行了您的代码,它从左侧开始,而不是从中心开始。是否正在添加数据?那套在哪里?
-
是的,我将状态用于数据
-
你能显示所有用于setData的代码吗?
-
@SajadSpeed 将
inverted={true}作为道具添加到 Flatlist 并检查。 -
不工作....
标签: react-native scroll center react-native-flatlist flatlist