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

Arrays in Kendo Models

1 Answer 164 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 22 Aug 2012, 03:52 PM
I'm working on a page where-by a user can edit an Item and a list of Versions for the item.  I'm trying to use Kendo Models for this for 3 reasons:
  1. I'm using the Model elsewhere to bind to a Kendo Grid
  2. The Model easily allows me to create new records as well as edit existing records
  3. I am making use of the Model's dirty flag and isNew() method to determine when changes need persisting and whether or not to call the create or update method of my transport.
Using models has been working great so far, but I ran into a glitch when dealing with nested data.

If I bind to an array directly within my view model, all is fine:
http://jsfiddle.net/jeffdev/LwS9Z/2/

But if I bind to an array with my model, it breaks:
http://jsfiddle.net/jeffdev/LwS9Z/3/ 

1 Answer, 1 is accepted

Sort by
0
Jeff
Top achievements
Rank 1
answered on 22 Aug 2012, 09:31 PM
It looks like Kendo's MVVM is not automatically converting arrays (or nested objects) to observables? (is that correct?)  I've been running some experiments and if I explicitly set my model's field to an observable array, then it seems to work (see: http://jsfiddle.net/jeffdev/LwS9Z/14/).

The trouble with doing it this way is that the parent model seems to have no knowledge of change events for the child objects.

In the case of my Fiddle, itemModel has no awareness of items being added, removed, or changed within the Versions field.

I'm trying to grab a record from the server, do some updates, and send the whole record back to the server (including its child array of Versions).

I love the concept of MVVM, but sometimes issues like this one seem to get tricky.  Am I better off abandoning MVVM and coding this up in some other fashion?
Tags
MVVM
Asked by
Jeff
Top achievements
Rank 1
Answers by
Jeff
Top achievements
Rank 1
Share this question
or