【发布时间】:2015-03-26 13:09:03
【问题描述】:
我正在关注本指南http://emberjs.com/guides/models/the-fixture-adapter/
我只是想在个性资源路径中显示我的夹具数据列表。我做错了什么?
浏览器控制台错误是:
处理路由时出错:personality.index attr is not defined ReferenceError: attr is not defined
一旦我尝试在我的路线中获取模型,模板就不再呈现。
路线/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`
我尝试使用我能想到的个性适配器的各种设置,但无济于事。
models/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
【问题讨论】:
-
如果您刚刚开始学习 Ember,请坚持使用默认设置、JavaScript 和 Handlebars。
-
我有 js2coffee。我对苗条感到满意
标签: ember.js ember-data ember-cli