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>
有帮助吗?

解决方案 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.

其他提示

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");
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top