如何使用Ember Data查找模型?

时间:2013-09-12 05:35:00

标签: ember.js ember-data

等同于

App.Person.find({age: 30})
<{3>}?

中的

即。如何根据属性获取记录数组?

2 个答案:

答案 0 :(得分:8)

ember数据1.0.0 beta2中的等效方法现在是:

this.store.find('person', {age: 30})

可以找到有关所有更改的更多信息here

希望它有所帮助。

答案 1 :(得分:8)

实际上有几种方法可以做到这一点。在此示例中,模型为“Org”,参数为名称为“AAA”的所有组织名称:

this.store.find('org', {'name' : 'AAA'})

或者

App.Org.store.find('org', {'name' : 'AAA'})

他们都会返回相同的Ember Promise数组。



要处理数组中的各个元素,您可以执行以下操作:

this.store.find('org', {'name' : 'AAA'}).then( function(result) {
     // do stuff with each result
});

类似地,

App.Org.store.find('org', {'name' : 'AAA'}).then( function(result) {
     // do stuff with each result
});



Everything here and more is shown in this jsbin, so you can compare and play yourself.不要忘记打开控制台来查看结果。

感谢Mike's comment

相关问题