Microsoft Lists时间线格式问题:富文本列显示HTML代码
修复Microsoft Lists时间线中富文本列显示HTML代码的问题
问题原因
将「Description」列转为「Enhanced rich text」后,该字段存储的是包含HTML标签的富文本内容,原JSON中使用的txtContent属性会把所有内容当作纯文本输出,导致HTML代码直接显示。
解决方案
把对应字段的txtContent替换为innerHTML,让浏览器解析HTML标签并渲染格式化文本。
修改后的完整JSON代码
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json", "hideSelection": true, "hideColumnHeader": true, "rowFormatter": { "elmType": "div", "style": { "display": "block", "width": "100%", "padding": "50px 0", "position": "relative", "overflow": "hidden" }, "children": [ { "elmType": "div", "attributes": { "class": "ms-bgColor-neutralQuaternary" }, "style": { "position": "absolute", "top": "0", "left": "50%", "margin-left": "-1px", "width": "2px", "height": "100%", "z-index": "1" } }, { "elmType": "div", "style": { "display": "flex", "width": "50%", "justify-content": "space-between", "float": "=if(@rowIndex % 2 == 0, 'left', 'right')", "flex-direction": "=if(@rowIndex % 2 == 0, 'row-reverse', 'row')", "margin": "=if(@rowIndex % 2 == 0, '0 0 0 8px', '0 8px 0 0')" }, "children": [ { "elmType": "div", "attributes": { "class": "ms-bgColor-themePrimary ms-borderColor-themeLighterAlt" }, "style": { "box-sizing": "border-box", "width": "16px", "height": "16px", "border-radius": "50%", "border-width": "2px", "border-style": "solid", "margin-top": "10px", "z-index": "9999" } }, { "elmType": "div", "style": { "box-sizing": "border-box", "width": "95%", "padding": "0 15px" }, "children": [ { "elmType": "div", "attributes": { "class": "ms-fontSize-32 ms-fontColor-themePrimary" }, "style": { "margin": "5px 0", "font-weight": "700", "text-align": "=if(@rowIndex % 2 == 0, 'right', 'left')" }, "txtContent": "[$Title]" }, { "elmType": "div", "attributes": { "class": "ms-fontSize-14" }, "style": { "line-height": "1.6em", "word-spacing": "1px", "font-weight": "600", "text-align": "=if(@rowIndex % 2 == 0, 'right', 'left')" }, "innerHTML": "[$Description]" } ] } ] } ] } }
修改点说明
仅修改了「Description」字段对应的渲染部分:将"txtContent": "[$Description]"替换为"innerHTML": "[$Description]"。
内容的提问来源于stack exchange,提问作者mariana
相关产品推荐
相关产品推荐

