I'm pretty new to Ember and I am having an issue pushing data to the store.
contact.js:model
import DS from 'ember-data';
export default DS.Model.extend({
//id: DS.attr(),
FirstName: DS.attr(),
Surname: DS.attr(),
EmailAddress: DS.attr()
});
index.js:route
import Ember from 'ember';
var contactresult = {};
var store = {};
export default Ember.Route.extend({
model(){
var headers = new Headers({
"Content-Type": "application/json",
});
var config = { method: 'GET',headers: headers};
contactresult = fetch('http://localhost:9000/api/Contact/GetAllUsers')
.then(function(response) {
//this.store.pushPayload(response);
return response.json();
});
store = this.store;
return contactresult;
}
,setupController(controller,model){
model.forEach(function(item, index, enumerable){
store.push(store.normalize('contact', item));
// {
// contacts:{
// id: item.Id,
// FirstName: item.FirstName,
// Surname: item.Surname,
// EmailAddress: item.EmailAddress
// }
// })
});
controller.set('model',model);
}
});
app.js
import Ember from 'ember';
import Resolver from 'ember/resolver';
import loadInitializers from 'ember/load-initializers';
import config from './config/environment';
import DS from 'ember-data';
let App;
Ember.MODEL_FACTORY_INJECTIONS = true;
App = Ember.Application.extend({
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix,
Resolver
});
loadInitializers(App, config.modulePrefix);
App.ContactSerializer = DS.RESTSerializer.extend({
normalizeFindAllResponse: function(store, primaryModelClass, payload, id,
requestType){
payload = {contacts: payload};
return this._super(store, primaryModelClass, payload, id, requestType);
},
normalizeFindRecordResponse: function(store, primaryModelClass, payload, id, requestType){
payload ={contact: payload} ;
return this._super(store, primaryModelClass, payload, id, requestType);
},
serializeIntoHash: function(hash,type, snapshot,option){
option = "";
var json = this.serialize(snapshot, {included:true});
Object.keys(json).forEach(function(key){
hash[key] = json[key];
});
}
});
export default App;
The error message I get back is: Error while processing route: index Cannot read property 'replace' of undefined TypeError: Cannot read property 'replace' of undefined
I can't seem to get around it, does anyone have any suggestions?
Aucun commentaire:
Enregistrer un commentaire