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

Datasource bound to form elements

1 Answer 216 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
cra
Top achievements
Rank 1
cra asked on 12 Jan 2016, 08:10 PM

Hello all,

 

I have a call to a service that will always return a single object with properties on said object. I have a form bound to a view model. I have a property on the view model that is a reference to the dataSource (service call) so that when I update the object I can call the dataSource.sync() method to save the changes back to the server.

 

This workflow works well with collections of items (grid). However I am having a tough time figuring out how to bind the form elements to the single object that is being returned by this specific service. the basics are as follows:

Create View Model

Create DataSource, then call .read() method. In the response from the read method I set a property on the viewModel vm.set("myProp", myDS)

Then in my HTML form I would like to bind elements to data from myDS. However if I do something like:

var data = myDS.view()[0];

vm.set("myProp", data);

I of course lose access to the sync() method.

 

What is the proper way to bind form field values to data from a dataSource object that will only ever have a single object returned?

 

Hope this makes sense.

 

Thanks for any and all help.

1 Answer, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 14 Jan 2016, 01:23 PM
Hello,

The DataSource is indeed designed to work with collections of items and is therefore not the best choice when working with a single object. I would recommend checking the Build MVVM Bound Forms With Kendo UI article for more details on that subject. 

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