Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.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
Node.js 通过本地节点js获取数据_Node.js_Mongodb_Sorting_Fetch - Fatal编程技术网

Node.js 通过本地节点js获取数据

Node.js 通过本地节点js获取数据,node.js,mongodb,sorting,fetch,Node.js,Mongodb,Sorting,Fetch,我试图从我的数据库中获取一些特定的数据,更具体、更清楚地说,这里有一个示例: 我的数据库中有客户,他们的文档如下: 客户1: _id:xxx 名称:abc 学分:100 客户2: _id:yyy 名称:abcde 学分:0 我想在平面列表中显示信用>0的客户的数据 我已经有了一个显示所有数据的平面列表,它工作正常, 我希望我是清楚的,谢谢 我正在使用react原生节点 class Listtest extends React.Component{ constructor() {

我试图从我的数据库中获取一些特定的数据,更具体、更清楚地说,这里有一个示例: 我的数据库中有客户,他们的文档如下:

客户1:
_id:xxx
名称:abc
学分:100

客户2:
_id:yyy
名称:abcde
学分:0

我想在平面列表中显示信用>0的客户的数据

我已经有了一个显示所有数据的平面列表,它工作正常, 我希望我是清楚的,谢谢

我正在使用react原生节点

    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={{flex:1}}>

    <TouchableOpacity
      onPress={()=>this.onPresino(item)}>
    <View style={{flexDirection:'row',padding:10}}> 
    
    <Avatar.Image
     source={{uri:'https://i.ibb.co/xDJ6XBd/Articleimage.jpg'}}
     size={50}/>
    <Text style= 
    {{marginVertical:10,marginLeft:20,letterSpacing:1.7,fontWeight:'bold',fontSize:20,marginLeft:8}}> 
    {item.Designation}</Text> 

    </View>
    </TouchableOpacity>

    </View>
    </Animated.View>
    )
    }
    renderSeparator =() => {
    return(
    <View
    style={{height:1,width:'100%',backgroundColor:'#ccc'}}>

    </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;



     
类Listtest扩展了React.Component{
构造函数(){
超级();
该值=8000;
此.state={
animatedValue:新的Animated.Value(0),
搜索:“”,
令人耳目一新:是的,
数据源:[],
孤岛加载:正确
}
}
OnPress=(项目)=>{
常数名称=项目名称;
const Marque=项目。Marque;
const PrixAchat=item.PrixAchat;
const PrixVente=item.PrixVente;
const MaxRemise=item.MaxRemise;
常量QuantiteAlerte=item.QuantiteAlerte;
常量QuantiteArticle=item.QuantiteArticle;
const Id_fourniseur=item.Id_fourniseur;
}
renderItem=({item})=>{
this.delayValue=this.delayValue+500;
const translateX=this.state.animatedValue.interpolate({
输入范围:[0,1],
outputRange:[this.delayValue,1]
});
返回(
此.onPresino(项目)}>
{项目名称}
)
}
RenderParator=()=>{
返回(
)
}
异步组件didmount(){
Animated.spring(this.state.animatedValue{
toValue:1,
张力:20,
useNativeDriver:真的吗
}).start();
待命http://localhost:8080/api/articles',{
方法:'get',
模式:'no-cors',
标题:{
“接受”:“应用程序/json”,
“内容类型”:“应用程序/json”
},
})
.then((response)=>response.json())
.然后((responseJson)=>{
这是我的国家({
数据来源:responseJson
})
})
.catch((错误)=>{
console.log(错误)
}
)}
render(){
返回(
{this.setState({search}}}
值={this.state.search}
style={style.search}
round=“默认值”
lightTheme=“默认值”
/>
索引}
ItemSeparatorComponent={this.renderSeparator}
/>
)}}
const styles=StyleSheet.create({
容器:{
身高:300,
弹性:1,
背景颜色:“#FFF”,
边界半径:6,
},
});
导出默认列表测试;
您可以简单地使用

value.credit>0)}
renderItem={this.renderItem}
keyExtractor={(项,索引)=>index}
ItemSeparatorComponent={this.renderSeparator}
/>

您可以使用状态值更改
0
,以便对其进行更多控制。

非常感谢,它工作得很好
<FlatList
  pagingEnabled
  data={this.state.dataSource.filter((value)=> value.credit > 0 )}
  renderItem={this.renderItem}
  keyExtractor={(item, index) => index}
  ItemSeparatorComponent={this.renderSeparator}
/>