gpt4 book ai didi

javascript - Ember 数据映射

转载 作者:行者123 更新时间:2023-12-02 18:58:16 25 4
gpt4 key购买 nike

我正在使用最新版本的 ember-data(修订版 11)和 REST 适配器从我的 API 中提取数据。返回的 JSON 示例如下所示:

{ 
"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'

最佳答案

乍一看,响应看起来很完美。

我的猜测是您为错误的请求发送了错误的格式。

此格式对许多事件有效,这意味着findAllfindQuery(GET/events )

但是,如果您针对单个 find 返回此响应 (GET/events/5118dd8c4c80866ef2000051)

在这种情况下(当您仅获取一个事件时),您的响应应如下所示:

{
"event": {
"id": "5118dd8c4c80866ef2000051",
"title": null,
// ... rest of attributes
}
}

关于javascript - Ember 数据映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15090618/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com