This is a migrated thread and some comments may be shown as answers.

Datasource.add and observableObject overridden

0 Answers 107 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Laurent
Top achievements
Rank 1
Laurent asked on 13 Apr 2012, 02:02 PM
Hi,

I've been using the last version with the MVVM and new DataSource, and I have a problem when adding an entity to a remote DataSource.

After sending the ajax request for adding a new entity, the response is merged with the entity.
This is done in dataSource._accept : 
if (type !== "destroy") {
models[idx].accept(response[idx]);

But the Model.accept will extends the model and will override all observable fields by the response from the server.
I have to modify the Model.accept method like this : 
             if (that instanceof ObservableObject) {
            that.init(data);
            } else {
                extend(that, data);
                if (that.idField) {
                    that.id = that.get(that.idField);
                }
            }

After the modification, my code works but I strongly believe it's not the good way.

Thanks in advance,

Laurent.


No answers yet. Maybe you can help?

Tags
Data Source
Asked by
Laurent
Top achievements
Rank 1
Share this question
or