Im trying to fetch some specific data from my database , To be more specific and clear here is an exemple: i have clients in my database , and here is how their documents looks like:
Client 1:
_id:xxx
name:abc
credit:100
Client 2:
_id:yyy
name:abcde
credit:0
i want to display the data of the clients who have an credit > 0 in a flatlist
i already have an flatlist which displays all data and it works fine , i hope i was clear, thanks!
Im using react native-nodejs
class Listtest extends React.Component{ constructor() { super(); this.delayValue = 8000; this.state = { animatedValue: new Animated.Value(0), search:'', refreshing: true, dataSource: [], isLoading:true } } onPresss = (item) => { const Designation = item.Designation; const Marque = item.Marque; const PrixAchat = item.PrixAchat; const PrixVente = item.PrixVente; const MaxRemise = item.MaxRemise; const QuantiteAlerte = item.QuantiteAlerte; const QuantiteArticle = item.QuantiteArticle; const Id_fournisseur = item.Id_fournisseur; } renderItem = ({item}) => { this.delayValue = this.delayValue + 500; const translateX = this.state.animatedValue.interpolate({ inputRange: [0, 1], outputRange: [this.delayValue,1] }); return( <Animated.View style={[styles.button, { transform: [{ translateX }] }]}> <View style=> <TouchableOpacity onPress={()=>this.onPresino(item)}> <View style=> <Avatar.Image source= size={50}/> <Text style= > {item.Designation}</Text> </View> </TouchableOpacity> </View> </Animated.View> ) } renderSeparator =() => { return( <View style=> </View> ) } async componentDidMount() { Animated.spring(this.state.animatedValue, { toValue: 1, tension: 20, useNativeDriver: true }).start(); await fetch ('http://localhost:8080/api/articles',{ method:'get', mode:'no-cors', headers:{ 'Accept':'application/json', 'Content-Type':'application/json' }, }) .then((response) => response.json()) .then((responseJson) => { this.setState({ dataSource:responseJson }) }) .catch((error) =>{ console.log(error) } )} render(){ return ( <View style={styles.container}> <SearchBar placeholder="Tapez ici..." onChangeText={search => { this.setState({ search }) }} value={this.state.search} style={styles.search} round="default" lightTheme="default" /> <FlatList pagingEnabled data={this.state.dataSource} renderItem={this.renderItem} keyExtractor={(item, index) => index} ItemSeparatorComponent={this.renderSeparator} /> </View> )}} const styles=StyleSheet.create({ container: { height: 300, flex:1, backgroundColor: '#FFF', borderRadius: 6, }, }); export default Listtest;
https://stackoverflow.com/questions/67308956/fetch-data-by-a-condition-react-native-node-js April 29, 2021 at 06:58AM
没有评论:
发表评论