【发布时间】:2019-10-07 11:16:51
【问题描述】:
我正在尝试将非数组 JSON 对象过滤为以下 sn-p
const filter = { filterRows: ['one'] };
const templateMapper = {
'one': {
title: 'one',
},
'two': {
title: 'two',
},
'three': {
title: 'three',
},
}
const filterDialogView = filter.filterRows;
const filterTemplateMapper = [templateMapper].filter(row => !filterDialogView.includes(row));
console.log(filterTemplateMapper);
但它没有过滤
我得到以下输出
[
{
"one": {
"title": "one"
},
"two": {
"title": "two"
},
"three": {
"title": "three"
}
}
]
渴望输出
{
"two": {
"title": "two"
},
"three": {
"title": "three"
}
}
我想根据 filterRows 过滤行,例如,如果 filterRows 包含 one 如上所述 JSON,则应从 templateMapper 中删除 one
【问题讨论】:
-
JSON 在哪里?我所看到的只是一个对象......并且无法使用 Array.filter 过滤对象,因为对象没有过滤方法
-
我正在使用 [templateMapper] 参见上面的代码我使用了 [] 数组
-
是的,但是该数组有一个条目 - 整个对象
标签: javascript node.js json filter