Question

I have a dojo widget with generated content, text message in my case.
Message text is a formatted text with <b>, <i> etc. tags. When I put it to my widget via ${messageText} it is shown as it is a plain text.

How to make my widget parse all these tags to DOM nodes?

upd .jsp fragment:

<script>
(new MyWidget({
    text: "<b>message</b>"
}).placeAt(dojo.byId("placeWidgetHere");
</script>

<div id="placeWidgetHere"></div>

widget .html template:

<div>${text}</div>
Était-ce utile?

La solution 2

The problem is that messageText has "<" and ">" symbols converted to "<" and ">" respectively. I added .replace(/&lt;/g, "<").replace(/&gt;/g, ">") to messageText and that began to work properly.

Thanks to everyone who tried to help me.

Autres conseils

Instead of using substitution variables (which is not recommended), you can use an attribute map on your custom widget.

<div>
    <span data-dojo-attach-point="messageTextNode"></span>
</div>


declare('MyWidget'], [TemplatedMixin], {
    template: ...,

    messageText: '',
     _setMessageTextAttr: { node: "messageTextNode", type: "innerHTML" },
});

new MyWidget({
    messageText: "<b>message</b>"
}, "placeWidgetHere");
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top