简体   繁体   中英

How to mount tags added dynamically

I have two files (dialog.tag) and (radio.tag) included in the page, compiled and mounted with command riot.mount('*')

I am trying to dynamically add DOM elements to the already mounted riot tag (dialog):

<dialog-tag id="dialog">
   <div ref="body"></div>
</dialog-tag>

in another script that runs after the previous tag is mounted:

let dialog = document.getElementById("dialog")._tag;
dialog.refs.body.innerHtml = "<div><radio label='some label'></radio></div>"

What I want to do is have the radio tags compiled after they are added to the dialog tag. Is there a way to so?

i think you are going at it in a wrong way. i'd suggest using the riot builtin tag yield for such things. It makes it simpler and cleaner. the tag definition:

<dialog-tag>
    </yield>
</dialog-tag>

then the usage

<dialog-tag id="kuku">

    dialog content... may include anything you want, including other tags

</dialog-tag>

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