gpt4 book ai didi

ember.js - Ember 数据错误 : "Assertion Failed: You need to pass a model name to the store' s modelFor method"

转载 作者:行者123 更新时间:2023-12-01 13:53:10 24 4
gpt4 key购买 nike

我在尝试从后端使用 json 时遇到此错误。我正在使用 Ember CLI 2.5.0 版和 RestAdapter。

这是我的 routes/products/index.js 的样子:

export default Ember.Route.extend({
actions: {
[...]
},
model: function() {
return this.store.findAll('product');
}
});

这是我的 json 的样子:

{
"products":[
{
"id":9,
"name":"Product A",
"price_cents":1500,
"margin_cents":0,
"commission":0,
"expiration":null,
"track_stock":false,
"stock_amount":5,
"brand":{
"id":2,
"name":"SuperPet"
},
"group":{
"id":1,
"name":"Group A"
}
},
{
"id":8,
"name":"Product B",
"price_cents":1500,
"margin_cents":0,
"commission":0,
"expiration":null,
"track_stock":false,
"stock_amount":5,
"brand":{
"id":1,
"name":"Whiskas"
},
"group":{
"id":1,
"name":"Group B"
}
}
],
"meta":{
"pagination":{
"per_page":null,
"total_pages":4,
"total_objects":10
}
}
}

根据要求,这是模型:

import DS from 'ember-data';

const { attr, belongsTo } = DS;

export default DS.Model.extend({
name: attr('string'),
priceCents: attr('number'),
marginCents: attr('number'),
comission: attr('number'),
expiration: attr('date'),
trackStock: attr('boolean'),
stockAmount: attr('number'),

brand: belongsTo('brand')

});

最佳答案

我遇到了同样的问题。这对我有用:

//app/serializers/product.js
import DS from 'ember-data';
import Ember from 'ember';

export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin,{
attrs: {
brand: { embedded: 'always' },
group: { embedded: 'always'}
}
});

关于ember.js - Ember 数据错误 : "Assertion Failed: You need to pass a model name to the store' s modelFor method",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37620567/

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