Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.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
Arrays 过滤本地数据_Arrays_Reactjs_Api_React Native_Fetch - Fatal编程技术网

Arrays 过滤本地数据

Arrays 过滤本地数据,arrays,reactjs,api,react-native,fetch,Arrays,Reactjs,Api,React Native,Fetch,我找了一整天,但没有找到解决问题的办法。 我是新来的土生土长的人,所以我被绊倒了 我的问题是: 我获取一个api来获取数据,我正在使用axios进行操作,我可以渲染我的组件 然后,我不想显示数组中的所有项目,但我想用两个按钮根据不同的值显示一些项目: <Button onPress={Get ALL ITEMS with this value}/> <Button onPress={Get ALL ITEMS with ANOTHER VALUE} /> 我确信这不是最

我找了一整天,但没有找到解决问题的办法。 我是新来的土生土长的人,所以我被绊倒了

我的问题是:

我获取一个api来获取数据,我正在使用axios进行操作,我可以渲染我的组件

然后,我不想显示数组中的所有项目,但我想用两个按钮根据不同的值显示一些项目:

<Button onPress={Get ALL ITEMS with this value}/>
<Button onPress={Get ALL ITEMS with ANOTHER VALUE} />
我确信这不是最好的方法,因为它不起作用。。我希望你能理解我想说的话


谢谢

< p>因为你似乎正在使用<代码>产品<代码>属性填充你的模板,考虑使用一个单独的变量来代替,这样你不必在你的过滤过程中弄乱你的状态。也许这会有帮助:

displayProducts = []

onPressFirstButton () {
  this.displayProducts = this.state.products.filter(product => /* logic */)
}

非常感谢你,本!我不知道为什么我没有想到那件事。。当然很明显…:-)
displayProducts = []

onPressFirstButton () {
  this.displayProducts = this.state.products.filter(product => /* logic */)
}