0

我正在尝试使用 Fixtures 将 Ember App Kit 与 Ember Data 一起使用(我正在使用最新的两者) - 但由于某种原因,我得到以下信息:

Assertion failed: No model was found for 'todo' [VM] ember.js (4005):415

Error while loading route: TypeError {} [VM] ember.js (4005):415

Uncaught TypeError: Cannot set property 'store' of undefined ember-data.js:2182

应用

import Resolver from 'resolver';
import registerComponents from 'appkit/utils/register_components';

var App = Ember.Application.extend({
  LOG_ACTIVE_GENERATION: true,
  LOG_MODULE_RESOLVER: true,
  LOG_TRANSITIONS: true,
  LOG_TRANSITIONS_INTERNAL: true,
  LOG_VIEW_LOOKUPS: true,
  modulePrefix: 'appkit', // TODO: loaded via config
  Resolver: Resolver
});

App.initializer({
  name: 'Register Components',
  initialize: function(container, application) {
    registerComponents(container);
  }
});

App.ApplicationAdapter = DS.FixtureAdapter.extend();

export default App;

索引路线

import Todo from 'appkit/models/Todo';

var IndexRoute = Ember.Route.extend({
  model: function() {
    return this.store.findAll('todo');
  }
});

export default IndexRoute;

待办事项模型

var Todo = DS.Model.extend({
  'title': DS.attr('string'),
  'user': DS.attr('object'),
  'comment': DS.attr('string'),
  'mood': DS.attr('string')
});

Todo.FIXTURES = [{ 
    'title': 'Received Hardware!', 
    'user': { 'username': 'alvincrespo' }, 
    'comment': 'Finally received my hardware!',
    'mood': 'happy'
}, {
    'title': 'This is honorable.', 
    'user': { 'username': 'robwolf' }, 
    'comment': 'I regret it already.',
    'mood': 'happy'
}, {
    'title': 'I can\'t seem to speak', 
    'user': { 'username': 'catstark' }, 
    'comment': 'Wait a minute, why am I hear?',
    'mood': 'sad'
}, {
    'title': 'Attendance is poor.', 
    'user': { 'username': 'cerlan' }, 
    'comment': 'Kings landing seems pretty empty after the war.',
    'mood': 'neutral'
}];

export default Todo;

我已经宣布了DS.FixtureAdapterapp.js但由于某种原因它仍然无法正常工作?有任何想法吗?

谢谢!

4

1 回答 1

0

我对寄存器组件的作用并不乐观。但本质上它是说它不知道 Todo 模型(通常它通过查找其命名空间中描述的模型来找到它,即 App.Todo = DS.Model.extend ....)

您可能还需要声明商店。

 App.Store = DS.Store.extend();

在 Ember Data 1.0 beta 1 中,您可以像这样进行适配器

 App.ApplicationAdapter = DS.MyRESTAdapter; // note you don't extend/create it
于 2013-10-06T19:40:19.180 回答