我想限制12中的帖子,只显示post_featured键值为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);
});
}
答案 0 :(得分:2)
我认为您在过滤器中遗漏了elem.
,请尝试以下操作:
posts: responseJson.filter((elem, index) => { return index < 12 && elem.post_featured == '1' })