Datasource bound to form elements

2 posts, 0 answers
  1. cra
    cra avatar
    16 posts
    Member since:
    Jun 2012

    Posted 12 Jan Link to this post

    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.

  2. Alexander Popov
    Alexander Popov avatar
    1411 posts

    Posted 14 Jan Link to this post


    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. 

    Alexander Popov
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top