You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

寻求实现对象属性批量映射与关联的JavaScript/Node.js库

寻找JavaScript/Node.js环境下的BulkMap同类库

嘿,我碰到了微服务里很常见的一种数据关联需求,具体流程是这样的:

  • 首先有一组源对象数组:
[ 
  {id: 1, name: "test", tagId: 1}, 
  {id: 2, name: "test", tagId: 15}, 
  {id: 3, name: "test", tagId: 5}
]
  • 第一步得提取其中tagId属性的唯一值,得到数组[1,15,5],接着调用批量处理方法(比如发起API请求):
async (ids) => await axios.get('http://apihost/tag', {id: ids})
  • 这个请求会返回标签数据数组:
[ 
  {id: 1, name: "tag1"}, 
  {id: 15, name: "tag2"}, 
  {id: 5, name: "tag3"}
]
  • 最后要把这些标签数据按ID关联回原对象,类似SQL的JOIN操作,得到最终结果:
[ 
  {id: 1, name: "test", tagId: 1, tag: {id: 1, name: "tag1"}}, 
  {id: 2, name: "test", tagId: 15, tag: {id: 15, name: "tag2"}}, 
  {id: 3, name: "test", tagId: 5, tag: {id: 5, name: "tag3"}}
]

我自己已经开发了PHP版本的BulkMap库,用起来很简洁,API示例如下:

new BulkMap(source).map( 'tagId', 'tag', async (ids) => axios.get('http://apihost/tag', {id: ids}) );

现在想找JavaScript/Node.js环境下的同类库,不知道有没有现成的能满足这个需求?

内容的提问来源于stack exchange,提问作者Mikhail Elfimov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:48:43