【发布时间】:2020-12-29 07:19:36
【问题描述】:
为了清楚起见,我在后端使用了 RTE 来存储一些描述。后来,通过 api,我收到了描述以及其他详细信息作为响应。现在风格完好无损。例如,粗体标题。但是当我使用 innerHTML 属性在 HTML 文档中呈现它时,我看到的只是未格式化的文本。标题不再是粗体。
这是回复的一部分:
</p>\r\n\n\r\n<p><span style=\"font-weight: bold;\">Features</span> \n </p>\r\n\n\r\n<p>Gives even skin tone, smoother complexion and sculpted facial features.
很明显,在这里可以看到 font-style="bold"。但在此之后,渲染版本不包含这些样式。
以下是完整回复:
"cart_count":2,
"images":[
],
"success":true,
"message":"Sucessfully",
"data":{
"product_id":1,
"name":"Dr G Butterfly Gua Sha",
"category_id":1,
"category":"Skin Tool",
"description":"<p>Dr G Butterfly Rose Quartz Gua Sha is a beauty and wellness tool designed to heal and enhance natural beauty. It lifts and sculpts your face, drains the lymph node, which reduces puffy eyes and face. By scraping with repeated strokes on the surface of the skin, this tool helps stimulate muscles and increases the blood flow. \n </p>\r\n\n\r\n<p><span style=\"font-weight: bold;\">Features</span> \n </p>\r\n\n\r\n<p>Gives even skin tone, smoother complexion and sculpted facial features. Reduces the signs of ageing and gives younger-looking skin. Increases lymphatic function. Stimulates blood circulation. Improves the appearance of dark circles and reduces under-eye puffiness. </p>\r\n\n\r\n<p><span style=\"font-weight: bold;\">How To Use \n</span></p>\r\n\n\r\n<p>Apply Dr G oil or Dr G gel as per your skin type covering the face and neck. </p>\r\n<p>Hold the butterfly gua sha tool firmly and sweep across gently up and out, starting with the neck, cheeks, jawline, chin, around the mouth, and slowly glide under the eyes, across your eyebrows and from your forehead up to your hairline. </p>\r\n<p>You can sweep it 3-5 times per area. </p>\r\n<p>Recommended at least a few times a week for best results. </p>\r\n\n\r\n<p><span style=\"font-weight: bold;\">About Dr G</span> \n </p>\r\n\n\r\n<p>Dr G offers luxury skincare products, backed by over a decade of dermatology expertise and on-ground practice. Made for Indian weather conditions, with variants for different skin types, including sensitive skin, and to address specific skin concerns - these innovative products are a perfect balance of nature and science. Drawing from ancient Ayurveda and combining natural extracts with skin-safe science, Dr G's range of products bridge modern skincare with holistic science.</p>",
"short_description":"Sculpts, Tones, Reduces Puffiness, Lifts",
"max_quantity":500,
"status":1,
"in_stock":1,
"measurement":[
{
"is_cart":true,
"ordered_quantity":2,
"is_wish":false,
"discounted_price":1400.0,
"weight":"200 Gram",
"price":1400.0,
"prod_id":1,
"percentage":100,
"max_quantity":500
}
]
}
}
【问题讨论】:
-
我必须看到后端的完整响应,但如果我不得不猜测,我会检查编码的引号是否是问题(即。\")。
-
@AldinBradaric,我最初也是这么想的。当作为响应发送时,文本是否被转换为字符串?知道这一点的唯一原因是客户可以在描述中以任何格式(粗体、斜体等)提供任何内容。我们只是不想硬编码任何东西。不过感谢您的帮助!
-
就像 Aldin Bradaric 所说,需要完整的回应来澄清这个问题。但是您应该先将您的 HTML 编码(例如 Base64 字符串),然后再将其发送到 frondend 并在那里解码。
-
我已经更新了完整的回复,请看一下。谢谢!