【发布时间】:2018-03-22 00:04:56
【问题描述】:
我有 const 数据,我需要 obj field company 的过滤卡数组 例如按公司:'Symu.co'
const data = {
lanes: [
{
id: 'lane1',
header: 'Quened',
label: '',
cards: [
{id: 'Task1', title: 'Wordpress theme', company: 'Symu.co', price: 1500, user: 'michelle'},
]
},
{
id: 'lane2',
header: 'Planning',
label: '',
cards: [
{id: 'Task2', title: 'Landing page', company: 'Google', price: 1500, user: 'jolene'},
{id: 'Task3', title: 'New website', company: 'Symu.co', price: 1500, user: 'lyall'},
{id: 'Task4', title: 'Dashboard', company: 'Microsoft', price: 1500, user: 'john'},
{id: 'Task5', title: 'Mobile App', company: 'Facebook', price: 1500, user: 'dominic'},
]
},
{
id: 'lane3',
header: 'Design',
label: '',
cards: [
{id: 'Task6', title: 'New Logo', company: 'Google', price: 1500, user: 'michelle'},
{id: 'Task7', title: 'New website', company: 'JCD.pl', price: 1500, user: 'dominic'},
{id: 'Task8', title: 'New website', company: 'Themeforest', price: 1500, user: 'john'},
{id: 'Task9', title: 'Dashboard', company: 'JCD.pl', price: 1500, user: 'jolene'},
]
},
{
id: 'lane4',
header: 'Development',
label: '()',
cards: [
{id: 'Task10', title: 'Mobile App', company: 'Facebook', price: 1500, user: 'john'},
{id: 'Task11', title: 'New website', company: 'Symu.co', price: 1500, user: 'michelle'},
{id: 'Task12', title: 'Dashboard', company: 'Google', price: 1500, user: 'dominic'},
]
},
{
id: 'lane5',
header: 'Testing',
label: '()',
cards: [
{id: 'Task13', title: 'Landing page', company: 'JCD.pl', price: 1500, user: 'lyall'},
]
},
{
id: 'lane6',
header: 'Production',
label: '()',
cards: [
{id: 'Task14', title: 'Landing page', company: 'Google', price: 1500, user: 'jolene'},
{id: 'Task15', title: 'New website', company: 'Themeforest', price: 1500, user: 'michelle'},
{id: 'Task16', title: 'Dashboard', company: 'Facebook', price: 1500, user: 'lyall'},
]
},
{
id: 'lane7',
header: 'Completed',
label: '()',
cards: [
{id: 'Task17', title: 'Mobile App', company: 'Facebook', price: 1500, user: 'john'},
{id: 'Task18', title: 'New website', company: 'Symu.co', price: 1500, user: 'michelle'},
]
},
]
};
我的代码,但我不知道该怎么做
for(let i = 0; i < data.lanes.length; i++) {
var changeCards = data.lanes[i].cards.filter(function(obj) {
return obj.company === 'Symu.co';
console.log(changeCards);
});
}
在输出中我需要获取新的 var 新数组作为示例 在输出中,我需要获取新的 var 新数组作为示例 在输出中,我需要获取新的 var 新数组作为示例 在输出中,我需要获取新的 var 新数组作为示例 在输出中,我需要获取新的 var 新数组作为示例 在输出中,我需要获取新的 var 新数组作为示例 在输出中我需要获取新的 var 新数组作为示例
var newArray = {
lanes: [
{
id: 'lane1',
header: 'Quened',
label: '',
cards: [
{id: 'Task1', title: 'Wordpress theme', company: 'Symu.co', price: 1500, user: 'michelle'
},
]
},
{
id: 'lane2',
header: 'Planning',
label: '',
cards: [
{id: 'Task3', title: 'New website', company: 'Symu.co', price: 1500, user: 'lyall'}
]
},
{
id: 'lane3',
header: 'Design',
label: '',
cards: [
]
},
{
id: 'lane4',
header: 'Development',
label: '()',
cards: [
{id: 'Task11', title: 'New website', company: 'Symu.co', price: 1500, user: 'michelle'},
]
},
{
id: 'lane5',
header: 'Testing',
label: '()',
cards: [
]
},
{
id: 'lane6',
header: 'Production',
label: '()',
cards: [
]
},
{
id: 'lane7',
header: 'Completed',
label: '()',
cards: [
{id: 'Task18', title: 'New website', company: 'Symu.co', price: 1500, user: 'michelle'},
]
},
]
};
但我不知道该怎么做
请帮忙!
非常感谢
【问题讨论】:
-
您需要提供代码来演示您尝试过的内容以及可能在哪里找到问题。
-
发布代码本身比截图更容易使用。
-
想要的输出是什么?
-
我编辑我想在输出中得到的内容
标签: javascript sorting filter array-filter