[英]React Native - How to merge User items and show on his profile?
What i have:我有的:
{"name": "author-1", "slug": {"_type": "slug", "current": "author-1-slug"}}
{"name": "author-2", "slug": {"_type": "slug", "current": "author-2-slug"}}
{"name": "author-1", "slug": {"_type": "slug", "current": "author-1-slug"}}
{"name": "author-3", "slug": {"_type": "slug", "current": "author-3-slug"}}
What i want:我想要的是:
{"name": "author-2", "slug": {"_type": "slug", "current": "author-2-slug"}}
{"name": "author-1", "slug": {"_type": "slug", "current": "author-1-slug"}}
{"name": "author-3", "slug": {"_type": "slug", "current": "author-3-slug"}}
What i tried:我尝试了什么:
const filtered = _.uniqBy(authors, 'slug')
//result [], [], [], []
Any solution?有什么解决办法吗?
If this is lodash function, you shoud try like this, if you don't want to have 2 same authors:如果这是 lodash function,如果你不想有 2 个相同的作者,你应该这样尝试:
const filtered = _.uniqBy(authors, 'name')
const uniqueTags = []; authors.map((item) => { var findItem = uniqueTags.find((x) => x.name === item.name); if (!findItem) uniqueTags.push(item); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.