mercredi 14 septembre 2016

ember transform not being used

In my app I'm trying to add a custom transformation for geo coordinates (my API is sending them as a string like "(latitude,longitude)" and I want them to be an object:

import DS from 'ember-data';

export default DS.Transform.extend({
    deserialize(serialized) {
        let deserialized = serialized.slice(1, -1);

        deserialized = deserialized.split(',');
        console.log('deserialize method');
        return {
            latitude: deserialized[0],
            longitude: deserialized[1]
        };
    },

    serialize(deserialized) {
        console.log('serialize method');
        return '(' + deserialized.latitude + ',' + deserialized.longitude + ')';
    }
});

I'm using ember-cli 2.7.0 and the code below is in the file app/transforms/coordinates.js

then in my model I'm using

geo: DS.attr('coordinates'),

but this doesn't work; the transform is not called at all (I can't see the logs) and the geo field is received as a string as it is sent from the API;

can someone help me to find out the problem here?




Aucun commentaire:

Enregistrer un commentaire