如何显示包含花括号的文本
How to display texts that contain curly braces
是否可以使用例如显示 JSON 字符串sap.m.Text
?
由于字符串 "{...}"
.
的结构,我很确定它将文本视为绑定语法
我认为可能有一个参数可以禁用允许任何类型的原始文本的绑定,但是查看 API,我没有看到这样的东西。
您可以使用 setText 方法将 JSON 视为字符串。
new sap.m.Text().setText(json);
带花括号的文本可以通过 sap.ui.base.ManagedObject.<strong>escapeSettingsValue</strong>
:
转义
new Text({
// ManagedObject required from "sap/ui/base/ManagedObject"
text: ManagedObject.escapeSettingsValue(myJSONText)
});
来自 API 参考:
escapeSettingsValue
Escapes the given value so it can be used in the constructor's settings object. Should be used when property values are initialized with static string values which could contain binding characters (curly braces)
这是一个演示:https://jsbin.com/bocuzaz/edit?js,output
先决条件
为了使escapeSettingsValue
工作,bootstrap设置compatVersion
需要设置为"edge"
。
是否可以使用例如显示 JSON 字符串sap.m.Text
?
由于字符串 "{...}"
.
我认为可能有一个参数可以禁用允许任何类型的原始文本的绑定,但是查看 API,我没有看到这样的东西。
您可以使用 setText 方法将 JSON 视为字符串。
new sap.m.Text().setText(json);
带花括号的文本可以通过 sap.ui.base.ManagedObject.<strong>escapeSettingsValue</strong>
:
new Text({
// ManagedObject required from "sap/ui/base/ManagedObject"
text: ManagedObject.escapeSettingsValue(myJSONText)
});
来自 API 参考:
escapeSettingsValue
Escapes the given value so it can be used in the constructor's settings object. Should be used when property values are initialized with static string values which could contain binding characters (curly braces)
这是一个演示:https://jsbin.com/bocuzaz/edit?js,output
先决条件
为了使escapeSettingsValue
工作,bootstrap设置compatVersion
需要设置为"edge"
。