Ember数据灯具适配器不加载所有数据 [英] Ember-data fixtures adapter not loading all data

查看:85
本文介绍了Ember数据灯具适配器不加载所有数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ember数据模型定义,看起来像这样

I have an ember-data model definition that 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适配器商店:

I have an ember-data fixture-adapter store set up like this:

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

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

...and fixtures which look like this:

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]
}];

(所有这些代码都在这个jsfiddle ,演示了这个问题。)

(All this code is in this jsfiddle which demonstrates the problem.)

这是一个问题:标题可以正常访问。 s子也在那里。 thumbnailUrl thumbnailWidth thumbnailHeight 都未定义。为什么?

Here's the issue: the title is accessible just fine. The slug is also there. The thumbnailUrl, thumbnailWidth, thumbnailHeight, are all undefined. Why?

推荐答案

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

You are not following ember-data's rails centric naming conventions. You can either change your fixture data to:

{
  "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]
}

或更改您的映射以包含一个键:

or change your mapping to include a key:

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

这篇关于Ember数据灯具适配器不加载所有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆