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

Updating/refreshing ViewModel in UI after Bind

1 Answer 1016 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Neeraj
Top achievements
Rank 1
Veteran
Neeraj asked on 12 Jun 2017, 11:13 AM

Hello,
          I have ViewModel that has Array. "TicketVMList"   .

Code:

TicketviewModel= kendo.observable({         

TicketVMList:  @Html.Raw(Json.Encode(Model)),         

GetTicketNumber: function(e) {             

                debugger;             

            GetTicketNumberProcess(e);        

            },         

OnTicketTstCheck: function(e) {

                          debugger;

                       OnTicketTSTCheckProcess(e);

          }     });

 

Initially it bind using :

kendo.bind($("#TicketItemContainer"), TicketviewModel.TicketVMList);   //works well

 

but there is click event on which i am making ajax call and i send this TicketVMList and it load some values inside it and send in response. On success i have tried various ways to refresh UI with new response that i received  ( TicketItemContainer is Div that i am binding to )

success: function (result) {                 debugger;                 
                    //kendo.unbind($("#TicketItemContainer"));                 
                    //kendo.bind($("#TicketItemContainer"),result);                 
                kendo.unbind($("#TicketItemContainer"));                 
              TicketviewModel.TicketVMList = result;                 kendo.bind($("#TicketItemContainer"), TicketviewModel.TicketVMList); 
                //var vm2 = kendo.observable(result);                 
            //$.extend(TicketviewModel.TicketVMList, vm2);                 //kendo.bind($("#TicketItemContainer"), TicketviewModel.TicketVMList); 
                kendo.ui.progress($("#TicketItemContainer"), false);             
},

 

 

Even have tried commented but it work.

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 14 Jun 2017, 08:34 AM
Hello Neeraj,

On the following Dojo example you will find a Kendo UI MVVM example which is identical to the described scenario.

I have setup a button, which requests data from a remote service and on success updates the ViewModel. To update the TicketVMList I have used the Kendo Model set() method as follows:
TicketviewModel.set("TicketVMList", data);

I hope this resolves your issue.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
MVVM
Asked by
Neeraj
Top achievements
Rank 1
Veteran
Answers by
Dimitar
Telerik team
Share this question
or