Ember-data fixtures适配器未加载所有数据

时间:2012-07-13 12:29:36

标签: ember.js ember-data

我有一个looks like this

的余烬数据模型定义
Sylvius.Filter = DS.Model.extend({
  title: DS.attr('string'),
  slug: DS.attr('string'),
  // Belongs to Atlas
  atlas: DS.belongsTo('Sylvius.Atlas'),
  // Has images
  images: DS.hasMany('Sylvius.Image'),
  // May have AtlasExtras
  extras: DS.hasMany('Sylvius.AtlasExtra'),
  // Structures for this filter
  structures: DS.hasMany('Sylvius.Structure'),
  // This is the path to the thumbnails sprite.
  // Each image will have an index on this sprite
  thumbnailUrl: DS.attr('string'),
  // How big is each thumbnail?
  thumbnailHeight: DS.attr('number'),
  thumbnailWidth: DS.attr('number'),
  // How big are the images? 
  imageHeight: DS.attr('number'),
  // which image is selected?
  selectedImage: DS.belongsTo('Sylvius.Image')
});

我有一个像这样设置的ember-data fixture-adapter商店:

Sylvius.fixtureStore = DS.Store.create({
  revision: 4,
  adapter: DS.fixtureAdapter
});

......和看起来像这样的灯具:

Sylvius.Filter.FIXTURES = [{
  "id": 1,
  "title": "Unlabeled",
  "slug": "unlabeled",
  "thumbnailUrl": "assets/img/surface_anatomy/photographic/srf-photo-unlabeled-tn.gif",
  "thumbnailWidth": 100,
  "thumbnailHeight": 75,
  "atlas_id": 1, 
  "images": [1, 2, 3, 4, 5, 6, 7],
  "structures": [0]
}];

(所有这些代码都在this jsfiddle中,以证明问题。)

以下是问题:标题可以访问得很好。 slu is也在那里。 thumbnailUrlthumbnailWidththumbnailHeight都未定义。为什么呢?

1 个答案:

答案 0 :(得分:6)

您没有遵循ember-data的以rails为中心的命名约定。您可以将夹具数据更改为:

{
  "id": 1,
  "title": "Dummy Title",
  "slug": "dummy-title",
  "thumbnail_url": "path/to/thumbnail.gif",
  "thumbnail_width": 100,
  "thumbnail_height": 75,
  "atlas_id": 1, 
  "images": [1, 2, 3, 4, 5, 6, 7],
  "structures": [0]
}

或更改您的映射以包含密钥:

thumbnailUrl: DS.attr('string', { key: 'thumbnailUrl' }),
thumbnailHeight: DS.attr('number', { key: 'thumbnailHeight' }),
thumbnailWidth: DS.attr('number', { key: 'thumbnailWidth' })