Ramda - 从多个对象的嵌套数组中获取 ID

Ramda - get ids from nested array of multiple objects

我正在尝试获取存储在对象内部数组中的 outgoingNodes ID,如下例所示,但我不知道从哪里开始...:[=​​12=]

const nodes = {
    "818": {
        "id": "818",
        "index": 1,
        "outgoingNodes": [
            "819"
        ],
    },
    "819": {
        "id": "819",
        "outgoingNodes": [
            "820",
            "821"
        ],
    }
}

我想得到一组 ID 作为结果。任何帮助将不胜感激。

获取值(子对象),提取 outgoingNodes 数组,并展平为单个数组:

const { pipe, values, pluck, flatten } = R

const fn = pipe(
  values,
  pluck('outgoingNodes'),
  flatten
)

const nodes = {"818":{"id":"818","index":1,"outgoingNodes":["819"]},"819":{"id":"819","outgoingNodes":["820","821"]}}

const result = fn(nodes)

console.log(result)
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.27.1/ramda.min.js" integrity="sha512-rZHvUXcc1zWKsxm7rJ8lVQuIr1oOmm7cShlvpV0gWf0RvbcJN6x96al/Rp2L2BI4a4ZkT2/YfVe/8YvB2UHzQw==" crossorigin="anonymous"></script>

另一种选择是结合获取 outgoingNodes 数组,并使用 R.chain 和 R.prop 展平为单个数组:

const { pipe, values, chain, prop } = R

const fn = pipe(
  values,
  chain(prop('outgoingNodes')),
)

const nodes = {"818":{"id":"818","index":1,"outgoingNodes":["819"]},"819":{"id":"819","outgoingNodes":["820","821"]}}

const result = fn(nodes)

console.log(result)
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.27.1/ramda.min.js" integrity="sha512-rZHvUXcc1zWKsxm7rJ8lVQuIr1oOmm7cShlvpV0gWf0RvbcJN6x96al/Rp2L2BI4a4ZkT2/YfVe/8YvB2UHzQw==" crossorigin="anonymous"></script>