Lodash: how do I use filter when I have nested Object?

前端 未结 5 527
滥情空心
滥情空心 2020-12-07 16:40

Consider this example. I am using Lodash

 \'data\': [
        {
            \'category\': {
                \'uri\': \'/categories/0b092e7c-4d2c-4eba-8c4e-80         


        
5条回答
  •  爱一瞬间的悲伤
    2020-12-07 17:00

    In lodash 4.x, you need to do:

    _.filter(summary.data, ['category.parent', 'Food'])
    

    (note the array wrapping around the second argument).

    This is equivalent to calling:

    _.filter(summary.data, _.matchesProperty('category.parent', 'Food'))
    

    Here are the docs for _.matchesProperty:

    // The `_.matchesProperty` iteratee shorthand.
    _.filter(users, ['active', false]);
    // => objects for ['fred']
    

提交回复
热议问题