我使用的是ember 2.7.0在我的一个ember服务中,我正在返回一个硬编码(尚未调用rest端点)数据,而是希望返回硬编码数据。在控制器中,如果promise是成功的,那么将硬编码的数据推到ember store中,否则返回错误object.I对于烬来说是全新的,所以我不知道如何实现这一点。在Ember中推送数据服务层中的数据并返回承诺
下面是我的服务文件
customer.js
import Ember from 'ember';
export default Ember.Service.extend({
getIndividualCustomer(id) {
// return Ember.$.ajax({
// url: `/api/v1/customers/${id}`,
// type: 'GET'
// });
return {
"customerId" : "38427357",
"productName":[{
"product":[{
"name":"sample1",
"status":"Active"
},{
"name":"sample2",
"status":"Active"
}]
}]
};
}
});
在上面的服务类,而不是返回硬编码的JSON我应该与此数据一起返回RSVP承诺。
下面是我的控制器文件
index.js
import Ember from 'ember';
export default Ember.Controller.extend({
customer: Ember.inject.service(),
actions: {
searchCustomer: function() {
this.store.push(this.store.normalize('customer', this.get('customer').getIndividualCustomer(this.get('inputID'))));
this.transitionToRoute('customers.view', this.get('inputID'));
},
}
});
下面是我的串行文件
customer.js
import ApplicationSerializer from './application';
export default ApplicationSerializer.extend({
primaryKey: 'customerId'
});
3-上述代码需要解决的问题:
1)必须从服务和数据一起返回承诺。
2)如何获取推送的数据(希望我推送的数据正确)。
3)运行上面的代码,而我收到以下异常,
Error: Ember Data Request GET /api/v1/customers returned a 404
这将是巨大的,如果有人指导我解决这些问题。
谢谢你的回答。我能够在你的帮助下完成它。清除所有的错误。 – VelNaga