[英]React Native - How to merge User items and show on his profile?
我有的:
{"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"}}
我想要的是:
{"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"}}
我嘗試了什么:
const filtered = _.uniqBy(authors, 'slug')
//result [], [], [], []
有什么解決辦法嗎?
如果這是 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.