1

我遇到了一个非常令人沮丧的问题,我的一些 ember-data 设备没有加载它们的种子数据。

这个可以很好地加载它的固定装置:

App.Place = DS.Model.extend
  name: DS.attr('string'),
  products: DS.hasMany('App.Product'),
  logo_url: DS.attr('string')

App.Place.FIXTURES = [
  {id: 1, name: 'Whataburger', logo_url: "..."},
  {id: 2, name: 'Holiday Lanes', logo_url: "..."},
  {id: 3, name: 'IHOP', logo_url: "..."},
  {id: 4, name: 'Johnny\s Pizza House', logo_url: "..."},
  {id: 5, name: 'Chilli\'s', logo_url: "..."},
  {id: 6, name: 'Church\'s Chicken', logo_url: "..."},
  {id: 7, name: 'Starbucks', logo_url: "..."},
  {id: 8, name: 'Coldstone', logo_url: "..."},
  {id: 9, name: 'Strawns Eat Shop', logo_url: "..."}
]

这个不加载它的固定装置:

App.Zoo = DS.Model.extend
  name: DS.attr('string'),
  logo_url: DS.attr('string')

App.Zoo.FIXTURES = [
  {id: 1, name: 'Foo', logo_url: "..."}
]

什么是交易?我在 chrome 扩展中看到了模型,并且所有字段都存在,只是没有记录。我正在使用版本为 1.0.0-rc.7 的 ember-source gem。Ember 数据是 0.13 版。

我的商店定义如下:

App.Store = DS.Store.extend
  adapter: DS.FixtureAdapter.create()

我的 ZooRoute 看起来像:

App.ZooRoute = Ember.Route.extend
  model: ->
    App.Zoo.find()
4

2 回答 2

2

这是由于最初没有定义路由器(仅适用于我的示例 Zoo 模型)和实际没有到达该路由 (/#/zoos) 的混淆组合。

事实证明,在您对该模型执行 a 之前,Ember 实际上不会将夹具加载到内存(仅模型)find中。

我现在可以点击 /#/zoos 路由并查看 Ember Chrome 扩展中加载的记录。

于 2013-09-01T15:18:05.710 回答
0

您的 FIXTURES 加载得很好,我根据您提供的代码创建了一个工作示例:http: //jsbin.com/odosoy/148/edit

您的应用程序中一定还有其他无法运行的东西,如果您有的话,也许在您的应用程序中ZoosRoute。尝试发布有关如何加载不工作的 FIXTURES 的更多详细信息。

希望能帮助到你。

于 2013-08-31T23:44:04.393 回答