Search code examples
javascriptbackbone.jsbackbone.js-collectionsbackbone-model

How to query nested object of a model in backbone using .where()


I have collection name @collection. Each model of @collection looks like this:

{
name : "example",
layout : {
    x : 100,
    y : 100,
  }
}

I have to do find models where model.attributes.layout[x] == '100'.

Can I do something like this @collection.where({layout[x] :100}) ? Or are there other ways to do such kind of query?


Solution

  • use filter method

    collection.filter(function(model) { return model.get('layout).x === 100; })