Yomguithereal / baobab

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

can't choose more item #466

Closed zodana closed 7 years ago

zodana commented 7 years ago

var tree=new Bab({ list:[ {name:"a",id:"1"}, {name:"a",id:"2"}, {name:"b",id:"3"} ] })

tree.select("list",{name:"a"}).get(); but return one record .

Yomguithereal commented 7 years ago

Yes, because you are creating a cursor and a cursor cannot select more than one node in the tree. Using a descriptor or function in the path works like using Array.prototype.find. For your use case, just do the following:

tree.select('list').get().filter(item => item.name === "a");