Javascript 如何在responseJson上使用两个属性?
我想把帖子限制在12个,并且只显示带有post_特色键值为1的特色帖子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,
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