gpt4 book ai didi

ember.js - 使用 EmberData 旁加载列出 "belongsTo"个对象

转载 作者:行者123 更新时间:2023-12-04 23:55:02 25 4
gpt4 key购买 nike

我有 3 个 emberData 模型:

App.Product = DS.Model.extend({
page_title: DS.attr('string'),
shop: DS.belongsTo('App.Shop'),
user: DS.belongsTo('App.User')
});

App.Shop = DS.Model.extend({
name: DS.attr('string'),
});

App.User = DS.Model.extend({
name: DS.attr('string')
});

JSON 数据如下所示:
{
products: [
{
id: "1",
page_title: "Product 1",
user_id: "1",
shop_id: "1",
},
{
id: "2",
page_title: "Product 2",
user_id: "2",
shop_id: "1",
}
],
users: [
{
id: "1",
name: "User 1"
},
{
id: "2",
name: "User 2"
}
],
shops: [
{
id: "1",
name: "Shop 1"
}
]
}

但是当我加载数据时,出现以下错误:
Assertion failed: Your server returned a hash with the key shops but you have no mapping for it 

最佳答案

好的,文档非常不清楚当您拥有 belongsTo 时这一事实。关系侧载的键必须是单数而不是复数,即使它是一个列表。所以 JSON 必须是这样的:

{
products: [
{
id: "1",
page_title: "Product 1",
user_id: "1",
shop_id: "1",
},
{
id: "2",
page_title: "Product 2",
user_id: "2",
shop_id: "1",
}
],
user: [
{
id: "1",
name: "User 1"
},
{
id: "2",
name: "User 2"
}
],
shop: [
{
id: "1",
name: "Shop 1"
}
]
}

关于ember.js - 使用 EmberData 旁加载列出 "belongsTo"个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17980538/

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