Javascript 按标题键筛选数组对象
我试图通过过滤“页面标题”键来获取每个数据。 这是我的示例json对象Javascript 按标题键筛选数组对象,javascript,angular,typescript,Javascript,Angular,Typescript,我试图通过过滤“页面标题”键来获取每个数据。 这是我的示例json对象 { "page_components": [ { "page_title": "My Account", "row_block": [ { "heading": "", "sub_heading": "We have been busy creating a place where you can find all your favorite saved pro
{
"page_components": [
{
"page_title": "My Account",
"row_block": [
{
"heading": "",
"sub_heading": "We have been busy creating a place where you can find all your favorite saved products and access our brand new tools.",
"header_image": {
"title": "Home-Loans-Sushi-Train",
"filename": "Home-Loans-Sushi-Train.png",
"url": "Home-Loans-Sushi-Train.png"
},
"show_gold_icon_list": false,
"show_blue_icon_list": false,
"show_cta_button": false
},
{
"heading": "Start comparing and saving",
"sub_heading": "",
"header_image": {
"title": "gold_logo",
"filename": "gold_logo.png",
"url": "gold_logo.png"
},
"show_gold_icon_list": true,
"show_blue_icon_list": false,
"show_cta_button": true,
"cta_button_text": "Compare",
"cta_button_color": "#008390",
"cta_button_link": ""
},
{
"heading": "Start comparing and saving using Blue",
"sub_heading": "",
"header_image": {
"title": "blue_logo",
"filename": "blue_logo.png",
"url": "blue_logo.png"
},
"show_gold_icon_list": false,
"show_blue_icon_list": true,
"show_cta_button": true,
"cta_button_text": "Compare with Blue",
"cta_button_color": "#008390",
"cta_button_link": ""
}
]
},
{
"page_title": "Saved Products",
"row_block": [
{
"heading": "You don’t have any saved products",
"sub_heading": "Save products that you’re interested in from the comparison table and find them here later.",
"header_image": {
"title": "gold_logo",
"filename": "gold_logo.png",
"url": "gold_logo.png"
},
"show_gold_icon_list": true,
"show_blue_icon_list": false,
"show_cta_button": true,
"cta_button_text": "Compare",
"cta_button_color": "#008390",
"cta_button_link": ""
},
{
"heading": "Saved products coming soon to Blue ",
"sub_heading": "",
"header_image": {
"title": "blue_logo",
"filename": "blue_logo.png",
"url": ""
},
"show_gold_icon_list": false,
"show_blue_icon_list": false,
"show_cta_button": true,
"cta_button_text": "Compare with Blue",
"cta_button_color": "#087DB2",
"cta_button_link": ""
}
]
},
{
"page_title": "Saved Shortlists",
"row_block": [
{
"heading": "You don’t have any saved shortlists with",
"sub_heading": "Save made by doing a three way comparison and find them here later.",
"header_image": {
"title": "gold_logo",
"filename": "gold_logo.png",
"url": ""
},
"show_gold_icon_list": true,
"show_blue_icon_list": false,
"show_cta_button": true,
"cta_button_text": "Compare",
"cta_button_color": "#008390",
"cta_button_link": ""
},
{
"heading": "Saved shortlists coming soon",
"sub_heading": "",
"header_image": {
"title": "blue_logo",
"filename": "blue_logo.png",
"url": ""
},
"show_gold_icon_list": false,
"show_blue_icon_list": false,
"show_cta_button": true,
"cta_button_text": "Compare with Blue",
"cta_button_color": "#087DB2",
"cta_button_link": ""
}
]
}
]
}
我想通过过滤页面标题来获得每一行块。目前我有这个代码,它似乎不工作。我不知道如何通过函数传递给定标题的每一行
getPageComponents(title: string) {
this.pageComponents.filter((page) => {
return page.page_title === title;
});
}
但我没能得到结果。有人能帮我在javascript中使用过滤器吗。提前感谢您缺少
return
关键字
getPageComponents(title: string) {
return this.pageComponents.filter((page) => {
return page.page_title === title;
});
}
我对打字本一点也不熟悉,但这不重要
.filter
不作用于阵列。。。它返回一个新数组。尝试将某个值设置为this.pageComponents.filter或将其返回。是否检查了标题参数数据?是否缺少return
keyword@MdMahamudulHasan是的,我已经检查过了。@Phong Omg。我想它现在起作用了。帮个大忙!!!太棒了