通过以下代码,我能够在sap ui5中使用富文本编辑器。
sap.ui.require(["sap/ui/richtexteditor/RichTextEditor", "sap/ui/richtexteditor/EditorType"],
function (RTE, EditorType) {
var oRichTextEditor = new RTE("myRTE", {
editorType: EditorType.TinyMCE4,
width: "100%",
height: "200px",
customToolbar: true,
showGroupFont: true,
showGroupLink: true,
showGroupInsert: true,
value: sHtmlValue,
ready: function () {
this.addButtonGroup("styleselect").addButtonGroup("table");
}
});
that.getView().byId("textarea").addContent(oRichTextEditor);
});现在客户端希望将默认字体系列和字体大小设置为Arial,并将大小设置为11。
您能告诉我如何设置这些默认值吗?
发布于 2020-04-28 20:42:31
开箱即用的RTE不支持11点。您必须增强有效字体大小的可用列表。
然后,在beforeEditorInit事件中,可以应用您的设置
sap.ui.require([
"sap/ui/richtexteditor/RichTextEditor",
"sap/ui/richtexteditor/EditorType",
"sap/ui/richtexteditor/library"
], (RTE, EditorType, RTELibrary) => {
// RTE only supports a few FontSizes out of the box. Add your additional FontSize here
const aFontSizes = RTELibrary.EditorCommands.FontSize;
aFontSizes.push(11);
aFontSizes.sort((a, b) => a - b);
const oRichTextEditor = new RTE("myRTE", {
editorType: EditorType.TinyMCE4,
customToolbar: true,
showGroupFont: true,
beforeEditorInit: function (oEvent) {
const oConfig = oEvent.getParameter("configuration");
const fnSuperSetup = oConfig.setup;
oConfig.setup = (oEditor) => {
// if you want you can call the original setup method here
fnSuperSetup(oEditor);
oEditor.on("init", function () {
oEditor.execCommand("FontName", false, "arial, helvetica, sans-serif");
oEditor.execCommand("FontSize", false, "11pt");
});
};
}
});
this.getView().byId("mainPage").addContent(oRichTextEditor);
});一个小缺点:下拉菜单没有选择正确的值(11磅)。但您可以在源代码中看到它实际上是11pt:

也许其他人知道为什么调用execCommand时dropdown不能正确更新(它只适用于比插入的元素小的元素)。
https://stackoverflow.com/questions/61478462
复制相似问题