vendredi 31 juillet 2015

Lodash search by startswith in an array

I'm creating a simple search that searches an array of objects that starts with a string passed from an input.

So I have this:

var items = [
    {id: 1, tags: ['foo']},
    {id: 2, tags: ['fish', 'ball']},
    {id: 3, tags: ['bar', 'goo']},
];

input.on(function(e) {
    var test = _.filter(items, function(item) {
         return _.includes(_.pluck(items, 'tags'), input.val());
    });
    console.log(test);
});

This always returns an empty array, I think i'm missing startsWith, how do I use it here in my implementation, or is there a better way of doing search like this?

Aucun commentaire:

Enregistrer un commentaire