mercredi 28 janvier 2015

Using postgres json field with ember data

I've got a rails api that spits out a postgres field of type json called colors. I've got a series of input fields that can be changed and I'm hoping the keys on this json object can be modified when each field changes, but the binding doesn't seem to be working as expected.


The data looks like:



"colors": { "primary_color": "#c43535", "secondary_color": "#0000FF" }


My inputs look like:



{{input type="text" class="form-control" value=model.colors.primary_color}}
{{input type="text" class="form-control" value=model.colors.secondary_color}}


This displays the correct color in the field, but when I update the field, the JSON object does not appear to be updated in the Ember Inspector.


Color Pickers


I've tried three different transforms so far:


json.js



export default DS.Transform.extend({

deserialize: function(serialized) {
return JSON.parse(serialized);
},

serialize: function(deserialized) {
return JSON.stringify(deserialized);
}

});


raw.js



import DS from 'ember-data';

export default DS.Transform.extend({

deserialize: function(serialized) {
return serialized;
},

serialize: function(deserialized) {
return deserialized;
}

});


object.js



export default DS.Transform.extend({

deserialize: function(serialized) {
return Ember.isNone(serialized) ? {} : serialized;
},

serialize: function(deserialized) {
return Ember.isNone(deserialized) ? {} : deserialized;
}

});


All appear to have the same result, that updating the fields does not modify the object. How do I serialize/bind/update a json object with ember-data like this?





Aucun commentaire:

Enregistrer un commentaire