lodash在哪里考虑嵌套数组元素的方法

时间:2014-12-23 16:05:24

标签: javascript lodash

lodash where方法在搜索时不考虑嵌套数组元素。考虑以下示例:

var foo = [
  {
    "id": "123",
    "elements": [
      {
        "id": "1231",
        "name": "foo1"
      },
      {
        "id": "1232",
        "name": "bar1"
      }
    ]
  },
  {
    "id": "456",
    "items": [
      {
        "id": "4561",
        "name": "foo2"
      },
      {
        "id": "4562",
        "name": "bar2"
      }
    ]
  }
]

_.where(foo, { 'id' : '123' } ) //works and returns the element
_.where(foo, { 'id' : '1231' } ) //fails.. trying to match the first element in the elements array. does not return matched element

lodash或其他JavaScript库中是否有API来执行深度搜索?

0 个答案:

没有答案