Event listeners on child template stops working after update

3 posts, 0 answers
  1. Denny
    Denny avatar
    4 posts
    Member since:
    Aug 2018

    Posted 14 Apr 2020 Link to this post

    I am using MVVM to render a master template and within that I am rendering a child template using the data-template attribute. The child template contains some html that I attach an event to via jQuery.

    I'm running into an issue where the event no longer fires in the child template after an update to the model.

    My real-world implementation is more complex but I have thrown together a simple example of the issue here:


    To reproduce the problem:

    1. Click "I always work" notice the alert appears
    2. Click "I stop working after updating input" notice the alert appears
    3. Change the value of the input text
    4. Click "I always work" and notice the alert is still working
    5. Click "I stop working after updating input" and notice the alert no longer appears

    Is this behavior expected?




  2. Denny
    Denny avatar
    4 posts
    Member since:
    Aug 2018

    Posted 15 Apr 2020 in reply to Denny Link to this post

    Looks like I found my answer based on this post: https://www.telerik.com/forums/using-this-in-source-binding-recreates-dom-after-changing-any-observable-field#oFz3sf9p2keJUNXb8sAR3w

    So using data-bind="source: this" wont work. Instead of binding to "this" I'm just going to add a property to my view model and bind that to the child template. Additionally I found if I need access to the view model data from the child I can use data-bind="value:parent().id"

  3. Martin
    Martin avatar
    309 posts

    Posted 16 Apr 2020 Link to this post

    Hello Denny,

    I am glad that you were able to find an appropriate solution. Thank you for sharing it so that other members may benefit from it as well.

    Feel free to contact us whenever you have further questions.

    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top