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

Bind to Single Record

2 Answers 112 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 06 Aug 2012, 09:45 PM
I'm in the midst of writing a single page application with routes.  The way the application functions is:
  1. DataSource with list of items is bound to a Kendo Grid
  2. User clicks an item on the Grid and is taken to a new route which contains the ID of the item the user selected.  Example: www.mydomain.com/#itemID=1
  3. This ID is used in a DataSource to refresh the item the user chose.  This is also done in case the user bookmarks the specific route.  In such an event the Grid can be bypassed.
The binding of the Grid works great and I'm able to capture the ID of the chosen item and redirect to my new route.  I'm also able to create a new datasource with the ID of the item selected and return data from the server.

Here's where I'm stuck.  I'm trying to bind the returned record to HTML controls using an MVVM pattern, but it seems the Kendo binding context assumes that DataSource is a collection (where in my case it's a single record).  What is the correct approach for this?  Is there a way to bind controls in a DIV to a single record in a DataSource?

2 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 09 Aug 2012, 06:54 PM
Hello Jeffrey,

The dataSource component operates with arrays of objects. If you want to bind a single record you have to either wrap it inside an array or retrieve it through a standard $.ajax request.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jeff
Top achievements
Rank 1
answered on 10 Aug 2012, 09:07 PM
Thanks Alexandar.  I already opted for using standard jQuery ajax for this.  When the values return from the server I wrap them inside an instance of my schema model so that the data can enjoy the same field definitions and validations as used by my data source.  So far so good :)
Tags
MVVM
Asked by
Jeff
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or