我正在使用最新版本的ember-data(修订版11)和REST适配器从我的API中提取数据。返回的JSON的样品看起来是这样的:Ember数据映射
{
"events": [
{
"id": "5118dd8c4c80866ef2000051",
"title": null,
"starts_at": 1361901600,
"ends_at": null,
"currency": "SEK",
"cents_door": 4000,
"cents_advance": null,
"price_door": "40.00 kr",
"price_advance": null,
"age_limit": null,
"venue_section": "PLAYHOUSE",
"description": null,
"url": null,
"repeats": null,
"repeats_until": null,
"venue_id": "nefertiti-jazz-club",
"act_ids": [ "marias-playhouse" ]
}
]
}
这个模型看起来是这样的:
App.Event = DS.Model.extend
title: DS.attr('string')
startsAt: DS.attr('number')
endsAt: DS.attr('number')
currency: DS.attr('string')
centsDoor: DS.attr('number')
centsAdvance: DS.attr('number')
priceDoor: DS.attr('string')
priceAdvance: DS.attr('string')
ageLimit: DS.attr('string')
venueSection: DS.attr('string')
description: DS.attr('string')
url: DS.attr('string')
repeats: DS.attr('string')
repeatsUntil: DS.attr('string')
venue: DS.belongsTo('App.Venue')
acts: DS.hasMany('App.Act')
但请求数据时,请求成功完成,但我在控制台中此错误:
Uncaught Error: assertion failed: Your server returned a hash with the key events but you have no mapping for it
任何想法这里怎么了?
===
更新:根据要求,我增加了一点我Ember.js应用程序。
我RESTAdapter设置:
DS.RESTAdapter.registerTransform 'raw',
deserialize: (serialized) ->
serialized
serialize: (deserialized) ->
deserialized
App.Store = DS.Store.extend
adapter: DS.RESTAdapter.create
url: LJ.CONFIG.api.url
revision: 11
和路线:
App.Router.map ->
this.resource 'events', ->
this.route 'new'
this.resource 'event', path: '/events/:event_id', ->
this.route 'edit'
this.resource 'venue', path: '/venues/:venue_id', ->
this.route 'edit'
this.resource 'events'
this.resource 'act', path: '/acts/:act_id', ->
this.route 'edit'
this.resource 'events'
this.route 'search', path: '/search/:term'
this.route 'doc', path: '/docs/:doc'
扫管笏?你能否纠正语法并进一步解释?这还是相关的吗? – netpoetica 2013-05-01 17:33:49