我是Ember的新手,到目前为止,一切都很简洁,给我留下了深刻的印象。尽管用EmberFire查询数据似乎有点奇怪。例如,在组件的js中,我可以用以下命令找到一条记录:
store.query('user', { orderBy: 'email', equalTo: email }).then((response) => {
// expect response to be an object, or an array of objects
// but its actually a class, and needs the following to return data
var user = response.get('content')[0]._data;
// now able to access properties as originally expected
console.log(user.email);
});虽然上面的方法很有效,但感觉并不是很优雅。我是不是遗漏了什么?据我所知,文档仅限于解释查询,因此,对于访问模型属性的正确方式的任何帮助都将不胜感激。
谢谢
发布于 2016-12-08 04:52:39
store.query返回解析为AdapterPopulatedRecordArray的promise。所以,是的,它应该返回一个类。
如果您期望只返回1条记录,那么您应该使用queryRecord。
store.queryRecord('user', { orderBy: 'email', equalTo: email }).then((user) => {
// now able to access properties as expected
console.log(user.get('email'));
});如果您期望超过1条记录,则继续使用query,您将能够遍历返回的用户结果。
发布于 2017-05-18 11:53:46
这个问题已经存在了一段时间了,这是因为在任何人编写一种优雅的方式来查询之前,EmberFire就已经被弃用了。
This add-on解决了这个问题,并将允许您使用filterCustom方法以几乎任何您能想象到的方式进行查询。
https://stackoverflow.com/questions/41015427
复制相似问题