使用具有ember-cli模型蓝图的灯具

时间:2014-08-11 17:36:54

标签: ember.js ember-data

好的,这可能只是一个基本的JS问题。我试图在ember-cli中创建一个模型。我已经使用蓝图制作了初始文件。这给了我

import DS from 'ember-data';

export default DS.Model.extend({

});

我如何为此添加灯具?

1 个答案:

答案 0 :(得分:1)

这是我使用灯具的一些代码。主要的是Recipe.reopenClass,Recipe.Fixtures并不正确。

import DS from 'ember-data';

var Recipe = DS.Model.extend({
  title: DS.attr('string'),
  steps: DS.attr(),
  description: DS.attr('string')
});

Recipe.reopenClass({
  FIXTURES: [
    {
      id: 1,
      title: "Spaghetti and meat",
      steps: ["Cook noodles", "add meat", "eat the food"],
      description: "ITS NOODLES AND MEAT"
    },

    {
      id: 2,
      title: "Gyro",
      steps: ["get lamb", "eat greek taco"],
      description: "ITS A TACO"
    }
  ]
});

export default Recipe;

然后在adapters / application.js

import DS from 'ember-data';

export default DS.FixtureAdapter.extend();

将此添加到您的Brocfile

app.import({
  development: 'vendor/ember-data/ember-data.js',
  production:  'vendor/ember-data/ember-data.prod.js'
}, {
  'ember-data': [
    'default'
  ]
});