Reputation: 1629
I'm using a DOJO JsonRestStore. I modify fields in the object.
What would be the proper procedure for persisting the modified object back to the datastore and REST service?
Update: Removed info about grid as it was not part of the problem.
Upvotes: 0
Views: 1988
Reputation: 1629
Apparently I had assumed that the returned item would be synchronized with the datastore. It doesn't appear so and must be updated manually using:
store.setValue(item, field, value);
I was also hoping for a command equivalent to JPA merge. If you overwrite the prior object with:
store.newItem( updatedVersionOfItem );
and the item has the same unique id, it will overwrite the old item similar to merge.
Does anyone know if there some sort of a factory that will create getters and setters for an item that will call store.setValue() for each field?
I imagine it would be something like the following:
var wrappedItem = itemWrapperFactory.createWrapper( item, store );
...
//Some where in createWrapper(...), this is just the concept
for (var itemField in itemFieldList)
this.__defineGetter__( itemField[index] , function(val){
store.setValue(item, itemField[index], val);
});
I am consider writing my own as its a neat piece of architecture.
Upvotes: 1
Reputation: 1978
Normally, a store.save() should be enough... If not, it means you have a problem between your grid and the store.
Upvotes: 1