gpt4 book ai didi

ember.js - Ember-data 夹具适配器未加载所有数据

转载 作者:行者123 更新时间:2023-12-05 00:33:51 26 4
gpt4 key购买 nike

我有一个 looks like this 的 Ember 数据模型定义:

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 store:
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 中,它演示了这个问题。)

问题是:标题可以正常访问。蛞蝓也在那里。 thumbnailUrl , thumbnailWidth , thumbnailHeight , 都是未定义的。为什么?

最佳答案

您没有遵循 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' })

关于ember.js - Ember-data 夹具适配器未加载所有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11470545/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com