soger
soger

Reputation: 41

Display specific value in Flatlist React native

I am trying to diplay a specific value from the render method in flatlist but when i use {item.Name[0]} it shows me all the first letters from all the Name values but i want the whole first Name.

 return (
    
    <View style={styles.container}>
    <FlatList 
      horizontal
      data={this.state.data}
      renderItem={({ item,index }) => (
        <View style={styles.card_template}  >
      
      <View style={styles.text_container}>
        <Text style={styles.card_title}>{item.Name[1]}</Text>
        <Text style={styles.card_subtitle}>{item.Phone} </Text>
      </View>
      
    </View>
      )}
    />
  </View>
    
   );
  }
}```

Upvotes: 0

Views: 1077

Answers (2)

yash sanghavi
yash sanghavi

Reputation: 430

I think Problem is resolved if you following solution:

<Text style={styles.card_title}>{item.Name}</Text>

then try.

Upvotes: 0

Sick Ranchez
Sick Ranchez

Reputation: 228

After the alert on markerClick do this:

var temp = this.state.data.filter(x=> x.Name != marker.Name);  
temp.unshift(marker);  
this.setState({data:temp}); 

And on the renderitems just use item.Name

You are moving the selected marker to the first place in the array and selected item will be always on top

Upvotes: 1

Related Questions