繁体   English   中英

ember.js和mongoDB通过ID查找对象

[英]ember.js and mongoDB find object by id

干杯! 我从具有ID的远程服务器获取Foo(例如)对象,该ID如下所示:

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"})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM