gpt4 book ai didi

javascript - 我如何在 responseJson 上使用两个属性?

转载 作者:行者123 更新时间:2023-11-30 14:37:27 25 4
gpt4 key购买 nike

我想限制 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);
});
}

最佳答案

我认为您的过滤器中缺少 elem.,试试这个:

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

关于javascript - 我如何在 responseJson 上使用两个属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50203003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com