干杯! 我从远程服务器获取带有 ID 的 Foo(例如)对象,如下所示:
id: "5110e8b5a8fefe71e0000197"
但是当我这样做时:
App.Foo.find("5110e8b5a8fefe71e0000197")
它返回对象数组,这是错误的,因为所有ID在mongo中都是uniq的。
> Array[112]
那么,如何让它发挥作用呢?
更新: 我的查找功能:
App.Foo.reopenClass({
allFoos: [],
find: function(){
$.ajax({
url: 'http://address/foos.json',
dataType: 'jsonp',
context: this,
success: function(data){
data.forEach(function(foo){
this.allFoos.addObject(App.Foo.create(foo))
}, this)
}
})
return this.allFoos;
}
});
最佳答案
尝试使用这个:
App.Foo.findOne({_id: "5110e8b5a8fefe71e0000197"})
关于javascript - ember.js 和 mongoDB 通过 id 查找对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14725976/