How to set the text property of a textblock with a string containing "\n"?

I need to dynamically insert a text string into a multiline textblock containing the ‘\n’ character and have the string show up as multiple lines.
The following code does not appear to work:
var tb = n.findObject(“textblock”)
if(tb != null)
tb.text = t;

where t = “Line1\nLine2\nLine3” and
var n = myDiagram.findNodeForKey(id);

The textblock shows the string unbroken at the newline chars.

However, if I insert the following line in the nodeDataArray and bind it it appears correctly or if I manually insert the same string in the chrome debugger it works.

Any suggestions?

I wasn’t able to reproduce this in my codepen here. Could you provide more detail about when you are updating the text, what version you’re running, and what browser is failing?

Did you execute your code within a transaction?

Yes, I use a transaction to wrap updating any of the diagram components. It has something to do with the data I am pulling back from a web service call. I can intercept the data in the chrome debugger, manually set the exact same string (e.g. “L1\nL2\nL3”) then it shows correctly in the text block. The original data is coming from a web service request that returns xml encoded with UTF-8.

Probably something really simple but on this one I can’t seem to see the forest through the trees… :)

Perhaps you need to change all the \n to \\n when you are saving or loading your JSON to/from the server, otherwise the \n may go from being a newline in the data to a newline in the JSON source itself, when you’re saving it.