正在获取查询查找的属性
Getting properties of Query Find
在我的ember应用程序的登录功能原型中,我使用路由根据给定的用户名查询商店。如果找不到该用户名,我的API将返回一个带有消息属性的对象。这是一条路线:
App.LoginRoute = Ember.Route.extend({
actions: {
getUsername: function(username){
this.store.find('user', {username: username}).then(function(user){
var eid = user.get('eid');
console.log(eid);
if (eid) {
self.controller.send('transition', "index");
}
else {
self.controller.set('model', "Oops! That's not right.");}
});
}
}
});`
如果数据库中存在用户名,API将发送回用户对象。如果用户名存在,它会加载到商店中,我可以在Ember Inspector中的Data下看到记录。但是,我不知道如何获取该用户对象的属性。
在.then
中,我传递返回的信息,并尝试调用该信息的.get
,但始终返回未定义的信息。
获取store.find('store', {query})
返回的属性的正确方法是什么?
find-by-query返回一个集合。
this.store.find('user', {username: username}).then(function(userCollection){
// this would be the user if it existed
var user = userCollection.get('firstObject');
self.controller.send('transition', "index");
});
当用户不存在时,您可能应该返回404错误代码,而不是有效的响应,然后点击promise的失败部分。
this.store.find('user', {username: username}).then(function(userCollection){
// this would be the user if it existed
var user = userCollection.get('firstObject');
self.controller.send('transition', "index");
}, function(){
// failure happened
self.controller.set('model', "Oops! That's not right.");}
});
相关文章:
- 在JScript 5.8/WSH中具有属性查找的函数名
- 基于分部属性查找HTML
- JavaScript-通过类似的属性查找对象,并将其推送到一个新的数组中
- 如何在javascript中按属性查找数组中的对象
- 按属性查找元素 jQuery
- 在 JavaScript 中按属性查找类实例
- 在对象上定义 getter,以便所有未定义的属性查找都返回 “”
- 余烬未正确初始化存储:无法读取未定义的属性“查找”
- 按数据属性查找和删除项目
- 按属性查找多维对象中的最低数值
- javascript/aunderline:在数组中按属性查找对象,并将它们组合
- 使用JSON中的某个属性查找子对象
- 使用CSS属性查找元素
- 如何在jQuery中通过属性查找数组中的元素
- 用AngularJS的方式在对象数组中根据对象的属性查找对象
- 量角器:根据属性查找元素
- ES6:通过数组中的一个属性查找对象
- 如何使用jQuery通过数据属性查找动态添加的元素
- 按动态属性查找
- jquery通过src属性查找元素