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

MVVM Cancel Changes

1 Answer 228 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 1
Patrick asked on 12 Nov 2012, 01:06 PM
I found similar posts but nothing that really addresses the concern.  Basically want to implement Cancel on a ViewModel.  I've created a fiddle http://jsfiddle.net/yN5Cd/1/
Pretty simple, just create a model and a schema.  Create  a datasource setting the schema.  Add the model to the datasource and call sync().  Bind the first and only item in the datasource to a template.

What I really want to is to able to cancel changes on the item in the datasource.  I do have a Cancel button and it calles cancelChanges on the datasource but results in a an empty dataSource. 

I don't see why it's so much different than editing a datasource bound to a listview.  The cancel works great when the datasource is populated using the transport url.  But when I add an item in the javascript, the datasource removes it as soon as cancelChanges is called.
I would expect the original state of the model to be restored and the model to remain in the datasource.

Thanks,

1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 15 Nov 2012, 10:46 AM
Hello Patrick,

The cancellChanges is used to revert the changes from the last sync when there is transport defined. Also when you change the item in the dataSource this wont change the viewModel because in your example the viewModel is is a reference to the first object in the dataSource. However when you cancel the changes the viewModel will continue to point to that old object in the dataSource (even that it is no longer an item from the dataSource's data).

As a work-around I prepared a jsfiddle with several changes in the transport and the viewModel structure which you can see here.

http://jsfiddle.net/yN5Cd/3/

All the best,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
MVVM
Asked by
Patrick
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or