dimanche 4 janvier 2015

get is not defined when trying to extends JSONSerializer

I try to define my custom serializer by extending DS.JSONSerialzer.


I pick the serialize function without modifications but when i run Ember,i get this error:



ReferenceError: get is not defined



This is my code :



import DS from 'ember-data';

export default DS.JSONSerializer.extend({
serialize: function(record, options) {
var json = {};
if (options && options.includeId) {
var id = get(record, 'id');
if (id) {
json[get(this, 'primaryKey')] = id;
}
}

record.eachAttribute(function(key, attribute) {
this.serializeAttribute(record, json, key, attribute);
}, this);
record.eachRelationship(function(key, relationship) {
if (relationship.kind === 'belongsTo') {
this.serializeBelongsTo(record, json, relationship);
} else if (relationship.kind === 'hasMany') {
this.serializeHasMany(record, json, relationship);
}
}, this);
return json;
},
});


I didn't change any code. This is the original. Why get is suddenly undefined? It's imported in ligne 1 in the original file JSONSerialiser


Can you help me?





Aucun commentaire:

Enregistrer un commentaire