문제

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