1

我正在使用 ember 数据:

// Version: v1.0.0-beta.3-2-ga01195b
// Last commit: a01195b (2013-10-01 19:41:06 -0700)

var App = Ember.Application.create();
App.Router.map(function() {
  this.resource("main");      
});

使用命名空间:

App.ApplicationAdapter = DS.RESTAdapter.extend({
  namespace: 'api'
});

Ember 模型:

App.Article = DS.Model.extend({
  title: DS.attr('string'),
  desc: DS.attr('string')
});

路线如下所示:

App.MainRoute = Ember.Route.extend({
  model: function() {
    console.log(this.store.find('article')); // isRejected: true, reason: Object has no method 'eachTransformedAttribute'
    this.store.find('article').then(function(results){console.log(results)}); //nothing
  }
});

这是数据:

{
  "articles": [{
    "_id": "5266057ee074693175000001",
    "__v": 0,
    "createdAt": "2013-10-22T04:56:30.631Z",
    "desc": "testing, testing",
    "title": "Basic",
    "id": "5266057ee074693175000001"
  }, {
    "_id": "5266057ee074693175000002",
    "__v": 0,
    "createdAt": "2013-10-22T04:56:30.636Z",
    "desc": "testing, testing",
    "title": "Basic2",
    "id": "5266057ee074693175000002"
  }, {
    "_id": "5266057ee074693175000003",
    "__v": 0,
    "createdAt": "2013-10-22T04:56:30.636Z",
    "desc": "testing, testing",
    "title": "Basic3",
    "id": "5266057ee074693175000003"
  }, {
    "_id": "5266057ee074693175000004",
    "__v": 0,
    "createdAt": "2013-10-22T04:56:30.636Z",
    "desc": "testing, testing",
    "title": "Basic4",
    "id": "5266057ee074693175000004"
  }]
}
4

1 回答 1

3

我正在使用ember-tools来管理项目构建。问题在于 ember-tools 默认构建将模型定义放置在 Route 之后。更新:这是因为我在不使用生成器的情况下手动创建了 Article 模型。(我已经使用了生成器并且正确创建了订单)

我已经通过手动更新 built: application.js 来修复它:

App.MainRoute = Ember.Route.extend({
  model: function() {
    return this.store.find('document');
  }
});

App.Article = DS.Model.extend({
  title: DS.attr('string'),
  file: DS.attr('string')
});

对此:

App.Article = DS.Model.extend({
  title: DS.attr('string'),
  file: DS.attr('string')
});

App.MainRoute = Ember.Route.extend({
  model: function() {
    return this.store.find('document');
  }
});

我通过检查一个工作应用程序解决了这个问题,并发现在 JSONSerializer applyTransforms() 类型中引用了不同的类型:

在此处输入图像描述

它应该是这样的命名空间模型类:

在此处输入图像描述

于 2013-10-22T16:50:00.607 回答