我尝试通过 mockjax 为 ember 数据建模 ajax 调用。
我的模型:
App.Service = DS.Model.extend({
name: DS.attr('string'),
service_prices: DS.hasMany('servicePrice')
});
App.ServicePrice = DS.Model.extend({
unit_price: DS.attr('number'),
qty_unit: DS.belongsTo('qtyUnit'),
service: DS.belongsTo('service')
});
App.QtyUnit = DS.Model.extend(Ember.Validations.Mixin, {
name: DS.attr('string'),
});
App.Order = DS.Model.extend({
service: DS.belongsTo('service'),
qty_unit:DS.belongsTo('qtyUnit'),
});
我尝试order
通过mockjax
. (按下按钮。)呼叫后根据控制台
MOCK GET: /orders/1
Object {url: "/orders/1", type: "GET", isLocal: false, global: true, processData: true…}
Ember 数据尝试第二次调用
GET http://run.jsbin.com/services/%3CApp.Service:ember518:1%3E 404 (Not Found)
首先我不明白为什么是第二个电话?服务按我的顺序加载 JSON
var order = {
"order" : {"id":1,"service":1,"qty_unit":4},
"service":[{"id":1,"name":"ENG-GER","service_prices":[1,2]}],
"servicePrices":[
{"id":1,"qty_unit":4,"unit_price":3},
{"id":2,"qty_unit":5,"unit_price":4}
],
"qtyUnits":[
{"id":4,"name":"character"},
{"id":5,"name":"word"},
{"id":6,"name":"sentence"}
]
};
以及为什么要尝试 ember-data 调用记录App.Service:ember518:1
而不是它的 id “1”?