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

Data Binding Not Showing

1 Answer 483 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
mike
Top achievements
Rank 1
mike asked on 14 Aug 2014, 04:56 PM
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);
}

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 18 Aug 2014, 10:58 AM
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!
 
Tags
MVVM
Asked by
mike
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or