简体   繁体   中英

How to process elements added or removed from DOM by Dart Web UI template

In (latest) Dart Web UI, what's the best way to process an element when it's added or removed from the DOM by a template? Ideally I'd like to register a callback right in the template, but that's not a requirement.

Background: I need to register/unregister certain DOM elements from two JS libraries (one of which is a JQuery plugin). Since my template uses loops and conditionals (and data binding), elements can come and go at any time, and I can't just register them after the initial rendering.

It is possible to add callbacks to your component's class that trigger when it is either created, inserted into the DOM, or removed from the DOM.

Web UI Specification: Lifecycle Methods

class MyComponent extends WebComponent {

  inserted() {
    // Do stuff when inserted into DOM.
  }

  removed() {
    // Do stuff when removed from DOM.
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM