Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android React Native-具有2列的FlatList未按预期运行_Android_Ios_React Native_React Native Flatlist - Fatal编程技术网

Android React Native-具有2列的FlatList未按预期运行

Android React Native-具有2列的FlatList未按预期运行,android,ios,react-native,react-native-flatlist,Android,Ios,React Native,React Native Flatlist,我使用的是一个有两列的平面列表,它可以很好地工作,除了几行之外,它需要完整的一行,而不是它的一半。我在Android和iOS上都有这个问题。我试图在Flatlist Github中提出一个问题,但没有用- index.toString()} renderItem={({item:rowData,index})=>{ if(rowData.country\u id==this.state.selectedCountryId) { 报税表( 此.props.citySelection(行数据, t

我使用的是一个有两列的平面列表,它可以很好地工作,除了几行之外,它需要完整的一行,而不是它的一半。我在Android和iOS上都有这个问题。我试图在Flatlist Github中提出一个问题,但没有用-

index.toString()}
renderItem={({item:rowData,index})=>{
if(rowData.country\u id==this.state.selectedCountryId)
{ 
报税表(
此.props.citySelection(行数据,
this.state.selectedView)}>
.{rowData.name}
); 
} 
}}/>
下面是获得结果的屏幕截图-


<>任何人都可以帮助我解决这个问题吗?

< P>你的代码中的问题是你有条件地渲染行项目,我认为你在列表中看到的空白是因为这些条件不满足那些项目

if(rowData.country\u id==this.state.selectedCountryId)

如果您需要基于某些选择渲染项目,则事先预处理/过滤数据,然后传递到FlatList

希望这会有帮助

<FlatList 
    vertical 
    numColumns={2} 
    extraData={this.state} 
    data={this.state.bikeCities} 
    style={styles.CityListView} 
    showsVerticalScrollIndicator={false} 
    keyExtractor={(item, index) => index.toString()} 
    renderItem={({item:rowData, index}) => { 
    if(rowData.country_id == this.state.selectedCountryId) 
    { 
    return( 
          <TouchableOpacity style={styles.FlatListStyle} 
            onPress={() => this.props.citySelection(rowData, 
            this.state.selectedView)}> 
              <Text style={styles.cityText}> . {rowData.name}</Text> 
          </TouchableOpacity> 
         ); 
    } 
}}/>