Reputation: 1148
Using:
Ember.VERSION : 1.0.0-rc.1
Handlebars.VERSION : 1.0.0-rc.3
jQuery.VERSION : 1.9.1
I've got a model built around a list of custom objects that are serialized ans deserialized using a custom transform. It looks like this :
DS.RESTAdapter.registerTransform('list', {
serialize: function(value) {
return value.mapProperty('line').join("\n");
},
deserialize: function(value) {
return (value || '').split(/\n/).
map(function(line) { return App.ListItem.new(line: line); });
}
});
App.ListItem = Ember.Object.extend({
line: ''
});
App.MySuperModel = DS.Model.extend({
list: DS.attr('list');
});
It works alright, the model gets dirty when I add or remove items in the list, but when I update a ListItem's line it doesn't get dirty nor return to its previous state when I rollback the transaction.
Has anyone any idea on how to get it to work ? I'd rather not use relationships for what is just a simple list and is persisted as such on my server.
Upvotes: 1
Views: 689
Reputation: 1148
Found a way to work around it, though I would still appreciate a cleaner method would anywone provide one.
What I did wrong was : I was manipulating the original array of lines, adding or removing lines, so ember didn't detect any change (no .set('lines', ...)) and it was rolling back to the original array that had been changed.
What I'm doing now is making a a new array of lines (using the handy .copy() method) and use .set('lines', ...) to tell my model its lines value has changed.
(conclusion : sleep on your problems, they tend to solve themselves ^^)
Upvotes: 2