Data Binding Not Showing

2 posts, 0 answers
  1. mike
    mike avatar
    4 posts
    Member since:
    Jul 2014

    Posted 14 Aug 2014 Link to this post

    data comes back from ajax call and after the extend JobViewModel has the field PatientFirstName and is populated
    however txt_FirstName is never populated with the value in PatientFirstName

    i do var JobViewModel = kendo.observable({     }); because I only want to work with what comes back fro the ajax call

    what do I have to do to get this to work?

    thanks

    <div id="content_wrapper">
      ....many divs deep
                  <input type="text" id="txt_FirstName"  data-bind="value: PatientFirstName" />
     
    </div>

    from ajax call
    success: function (data) {
     var JobViewModel = kendo.observable({     });
                $.extend(JobViewModel, data);
                kendo.bind($("#content_wrapper"), JobViewModel);
    }
  2. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 18 Aug 2014 Link to this post

    Hi Mike,

    You should either create a ViewModel from the object that the server sends, or use the set method to update the fields of an existing ViewModel. Please check the following example:

    success: function (data) {
      var JobViewModel = kendo.observable(data);
      kendo.bind($("#content_wrapper"), JobViewModel);
    }

    or

    success: function (data) {
      var JobViewModel = kendo.observable({     });
     
      JobViewModel.set("firstName", data.firstName);
      JobViewModel.set("lastName", data.lastName);
     
      kendo.bind($("#content_wrapper"), JobViewModel);
    }

    I hope this will help.

    Regards,
    Alexander Valchev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
Back to Top