首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >fixtures中的嵌入对象会引发"unable to find fixtures“错误

fixtures中的嵌入对象会引发"unable to find fixtures“错误
EN

Stack Overflow用户
提问于 2012-08-24 23:23:15
回答 1查看 2.4K关注 0票数 1

我正在广泛使用ember- data的fixtures适配器来在我的应用程序中提供大量的设置数据。对于一个模型(“结构”),有一组嵌入的相关对象(“覆盖”)。当我从存储中加载一个结构实例,然后查询它的overlays属性时,我得到了这个错误:

代码语言:javascript
复制
Uncaught Error: assertion failed: Unable to find fixtures for model type App.Overlay

这两个模型的定义如下(为清楚起见,删除了一些其他字段/关系):

代码语言:javascript
复制
App.Structure = DS.Model.extend({
  // How this appears in lists
  name: DS.attr('string'),
  // Color to show this overlay with
  color: DS.attr('string'),
  // hash of overlay paths
  overlays: DS.hasMany('App.Overlay', { embedded: true })
});

App.Overlay = DS.Model.extend({
  view: DS.attr('string'),
  path: DS.attr('string')
});

我只需要一个固定装置来演示:

代码语言:javascript
复制
App.Structure.FIXTURES = [{
    "id": 0,
    "name": "Test Structure",
    "color": "#cc0033",
    "overlays": [{
        'view': 'Isometric',
        'path': "M17.5,19.508V8.626h-3.999v10.881c-1.404,0.727-2.375,2.178-2.375,3.869c0,2.416,1.959,4.375,4.375,4.375s4.375-1.959,4.375-4.375C19.876,21.686,18.905,20.234,17.5,19.508zM20.5,5.249c0-2.757-2.244-5-5.001-5s-4.998,2.244-4.998,5v12.726c-1.497,1.373-2.376,3.314-2.376,5.4c0,4.066,3.31,7.377,7.376,7.377s7.374-3.311,7.374-7.377c0-2.086-0.878-4.029-2.375-5.402V5.249zM20.875,23.377c0,2.963-2.41,5.373-5.375,5.373c-2.962,0-5.373-2.41-5.373-5.373c0-1.795,0.896-3.443,2.376-4.438V5.251c0-1.654,1.343-3,2.997-3s3,1.345,3,3v13.688C19.979,19.934,20.875,21.582,20.875,23.377zM22.084,8.626l4.5,2.598V6.029L22.084,8.626z"
    }]
}];

有了这些,我可以加载一个结构:

代码语言:javascript
复制
> var structure = App.fixtureStore.find(App.Structure, 0);
> structure.get('name');
"Test Structure"

但是如果我查询它的覆盖,事情就会变得很奇怪:

代码语言:javascript
复制
> structure.get('overlays');
Uncaught Error: assertion failed: Unable to find fixtures for model type App.Overlay

出什么事啦?我需要为这个模型声明fixture吗,即使它们是空的?

Here is a jsfiddle showing the error

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-24 23:33:32

啊,a little more tweaking to the fiddle表明我确实需要为模型声明空的fixture:

代码语言:javascript
复制
App.Overlay.FIXTURES = [];
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12112279

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档