Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/421.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
Javascript 如何在responseJson上使用两个属性?_Javascript_Reactjs_React Native - Fatal编程技术网

Javascript 如何在responseJson上使用两个属性?

Javascript 如何在responseJson上使用两个属性?,javascript,reactjs,react-native,Javascript,Reactjs,React Native,我想把帖子限制在12个,并且只显示带有post_特色键值为1的特色帖子 componentDidMount() { return fetch(ConfigApp.URL+'json/data_posts.php') .then((response) => response.json()) .then((responseJson) => { this.setState({ isLoading: false,

我想把帖子限制在12个,并且只显示带有post_特色键值为1的特色帖子

componentDidMount() {

   return fetch(ConfigApp.URL+'json/data_posts.php')
     .then((response) => response.json())
     .then((responseJson) => {
       this.setState({
         isLoading: false,
         posts: responseJson.filter((elem, index) => { return index < 12 && post_featured == '1' })
       }, function() {
       });
     })
     .catch((error) => {
       console.error(error);
     });
 }
componentDidMount(){
返回fetch(ConfigApp.URL+'json/data\u posts.php')
.then((response)=>response.json())
.然后((responseJson)=>{
这是我的国家({
孤岛加载:false,
posts:responseJson.filter((元素,索引)=>{returnindex<12&&post\u featured=='1'})
},函数(){
});
})
.catch((错误)=>{
控制台错误(error);
});
}

我认为您缺少
元素。
在您的筛选器中,请尝试以下操作:

posts: responseJson.filter((elem, index) => { return index < 12 && elem.post_featured == '1' })
posts:responseJson.filter((elem,index)=>{returnindex<12&&elem.post\u featured==1})

具体问题是什么?您提供了一个目标和一些代码,但没有关于该代码或错误的问题描述。解释该代码按预期为您做了什么或没有做什么。花几分钟时间阅读Sure thing@bdroid