Forcing MVVM View to update after view-model changes

2 posts, 0 answers
  1. Jairo
    Jairo avatar
    6 posts
    Member since:
    Mar 2017

    Posted 23 Jun Link to this post

    Hello,

    So I read some of the Kendo documentation regarding MVVM and it says that once the view model is updated the view (HTML) should update as well. 

    I tried that many times and when I change the viewModel from javascript I don't see the changes updated in the HTML unless I trigger the change event, as shown here:

    https://jsfiddle.net/oycbw9e6/

    You will notice that if you comment out this line: viewModel.trigger("change", { field: "price"}); then the changes won't be propagated to the HTML view.

    Is there any way it can be done automatically without triggering the "change" event?

    Thanks!

  2. Dimitar
    Admin
    Dimitar avatar
    176 posts

    Posted 27 Jun Link to this post

    Hello Jairo,

    On the following Dojo example you will find a modified version of your code. You will notice that I have changed the direct assignment of the ViewModel property to use the ObservableObject's set method which has an internal change tracking mechanism. 

    In addition to the above, I have added a button with a click event binding, which also changes the value by using the set() method. 

    I hope this helps. In case you have any other questions, please do not hesitate to contact us.

    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.
Back to Top