OpenUI5 - sap.m.Text issue with displaying JSON st

2019-08-07 12:52发布

问题:

Is it possible to display a JSON string using sap.m.Text

I'm pretty sure it's treating it as a binding due to the structure of the string "{...}"

I thought there may be a parameter to disable binding allowing any kind of raw text, but looking at the API I see no such thing.

https://openui5.hana.ondemand.com/docs/api/symbols/sap.m.Text.html#constructor

Here's an example of the issue:

http://jsbin.com/zarijedaya/1/edit?html,js,output

回答1:

You can make use of the setText method which will consider the JSON as a string.

new sap.m.Text().setText(json);

http://jsbin.com/bonoxavilo/1/edit