Ember CLI - 未显示夹具数据

时间:2015-03-26 13:09:03

标签: ember.js ember-data ember-cli

我正在遵循本指南http://emberjs.com/guides/models/the-fixture-adapter/

我只是想在个性资源路线中显示我的灯具数据列表。我做错了什么?

浏览器控制台错误是:

  

处理路径时出错:未定义personality.index attr ReferenceError:未定义attr


一旦我尝试在路线中获取模型,模板就不再渲染。

路由/ personalities.coffee

`import Ember from 'ember'`

PersonalitiesRoute = Ember.Route.extend
  model: ->
    this.get(store).find('personality')

`export default PersonalitiesRoute`

以上是破坏应用程序的代码部分(编译,但不显示任何内容)。我究竟做错了什么?

我的适配器,模板和模型如下

我确保使用夹具适配器 适配器/ application.coffee

`import DS from 'ember-data'`

ApplicationAdapter = DS.FixtureAdapter.extend()    

`export default ApplicationAdapter`

适配器/ personalities.coffee

`import ApplicationAdapter from './application'`

PersonalitiesAdapter = ApplicationAdapter.extend()
    #I also tried... = DS.FixtureAdapter.extend()
    #I also tried getting rid of PersonalitiesAdapter
    #I also tried PersonalityAdapter (singular, since that matches the model, which is singular)

`export default PersonalitiesAdapter`

我尝试使用我能想到的个性适配器的各种设置,但无济于事。

模型/ personality.coffee

`import DS from 'ember-data'`

Personality = DS.Model.extend
  id:           attr('number')
  type:         attr('string')
  socType:      attr('string')

Personality.reopenClass
  FIXTURES: [
    { id: 1,  type: 'entp', socType: 'NLE' }
    { id: 2,  type: 'isfp', socType: 'SFI' }
    { id: 3,  type: 'esfj', socType: 'ESE' }
    { id: 4,  type: 'intj', socType: 'LII' }
    { id: 5,  type: 'enfj', socType: 'EIE' }
    { id: 6,  type: 'istj', socType: 'LSI' }
    { id: 7,  type: 'estp', socType: 'SLE' }
    { id: 8,  type: 'infp', socType: 'IEI' }
    { id: 9,  type: 'esfp', socType: 'SEE' }
    { id: 10, type: 'intp', socType: 'ILI' }  
    { id: 11, type: 'entj', socType: 'LIE' }
    { id: 12, type: 'isfj', socType: 'ESI' }
    { id: 13, type: 'estj', socType: 'LSE' }
    { id: 14, type: 'infj', socType: 'FII' }
    { id: 15, type: 'enfp', socType: 'NEE' }
    { id: 16, type: 'istp', socType: 'SLI' }
  ]

`export default Personality`

模板/ personalities.emblem

= each item in model
  = item.id
  = item.type
  = item.socType
  = item.description

1 个答案:

答案 0 :(得分:1)

Personality = DS.Model.extend
  id:           attr('number')
  type:         attr('string')
  socType:      attr('string')

应该是

Personality = DS.Model.extend
  id:           DS.attr('number')
  type:         DS.attr('string')
  socType:      DS.attr('string')