Yomguithereal / baobab

JavaScript & TypeScript persistent and optionally immutable data tree with cursors.
MIT License
3.15k stars 116 forks source link

Get/Select on Various Array Entries #449

Closed jemos closed 8 years ago

jemos commented 8 years ago

Hi,

Is it possible to use .get({param: value}) and it return all the entries that have the property param = value?

As far as I know it will only return the first element found.

Thank you.

davincho commented 8 years ago

Hi, I think it is not possible. But there is an easy solution for your problem:

{
  items: [{
    id: 1,
    name: 'Item1'
  }, {
    id: 2,
    name: 'Item1'
  }]
}

var result = tree.get('items').filter(function(item) {
  return item.name === 'Item1';
});
jemos commented 8 years ago

Thanks for that hint davincho.