如何使用Ember Data查找模型?

Hao*_* Li 0 ember.js ember-data

什么相当于

App.Person.find({age: 30})
Run Code Online (Sandbox Code Playgroud)

新的Ember数据

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

int*_*xel 8

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

this.store.find('person', {age: 30})
Run Code Online (Sandbox Code Playgroud)

有关所有更改的更多信息,请点击此处.

希望能帮助到你.


Hao*_* Li 8

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

this.store.find('org', {'name' : 'AAA'})
Run Code Online (Sandbox Code Playgroud)

要么

App.Org.store.find('org', {'name' : 'AAA'})
Run Code Online (Sandbox Code Playgroud)

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



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

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

同样的,

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



这个和更多的东西都显示在这个jsbin中,所以你可以比较和玩自己.不要忘记打开控制台来查看结果.

感谢Mike的评论.