如何使用.where()查询骨干模型的嵌套对象

时间:2016-08-18 10:00:33

标签: javascript backbone.js backbone-collections backbone-model

我有收集名称@collection。每个@collection模型都是这样的:

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

我必须找到模特在哪里 model.attributes.layout[x] == '100'

我可以这样做@collection.where({layout[x] :100})吗?或者还有其他方法可以进行此类查询吗?

1 个答案:

答案 0 :(得分:1)

使用filter方法

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