0
我有这样的代码中的路由/ index.js:工作流与余烬数据和AJAX API呼叫
model() {
return Ember.RSVP.hash({
maps: ajax({
url: '*********************',
type: 'get'
}).then(function(data) {
console.log('maps: ', data);
return data;
})
});
}
返回JSON数据。现在我想与Ember数据和模型的工作,我有这个代码在型号/ map.js:
import DS from "ember-data";
export default DS.Model.extend({
gmap_lat_center: DS.attr('string'),
gmap_long_center: DS.attr('string'),
hotspots: DS.attr('array'),
id: DS.attr('string'),
image: DS.attr('array'),
image_highres: DS.attr('string'),
image_lowres: DS.attr('string'),
map_background: DS.attr('string'),
ne_lat: DS.attr('string'),
ne_long: DS.attr('string'),
order: DS.attr('string'),
sw_lat: DS.attr('string'),
sw_long: DS.attr('string'),
timestmap: DS.attr('string'),
title: DS.attr('string'),
track_geojson: DS.attr('string'),
type: DS.attr('string'),
zoom: DS.attr('string')
});
现在是什么应该是用Ajax和灰烬数据的工作流程?我需要在哪里放置ajax调用,并将它存储在模型中?
编辑: 我设法将它们推到店,但是当我尝试访问它:
this.store.pushPayload(normalizedData);;
console.log("maps: ", normalizedData);
console.log(this.store.findAll('map'));
return normalizedData;
我得到:
http://localhost:4200/maps 404 (Not Found)
我想我需要重写的findAll方法在一个适配器中,但这种方法将如何看起来像?
谢谢,但我在哪里需要把Ajax调用?我无法在指南中的任何地方找到它.. –
'findAll()'方法执行ajax请求。你不需要直接调用'ajax()'。使用指南中列出的方法:findRecord(),findAll(),queryRecord(),query(),createRecord(),save(),deleteRecord() 'destroyRecord()'。 https://guides.emberjs.com/v2.3.0/models/ –
所以像这样var posts = this.store.findAll('post');.不完全清楚我需要放置findAll方法的位置,在指南中没有提及。 –