首页 > 解决方案 > 如何添加链接并突出显示从 json 文件接收到的数据

问题描述

如何向从 json 文件接收的数据添加链接和格式(文本粗体、下划线或增加字体大小)。请找到以下示例 json 文件。

    {
        "Header": "Sample Header",
        "Head": "Click on “Accept” if you consent to the Terms and Conditions listed below or select “Decline” if you do not consent.",
        "Description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. It www.google.com was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. \\n **Heading** \\n  1.) It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout."
}

在 js 文件中使用以下代码从 json 文件接收数据。

import terms from "./TermsAndCondition.json";

let desc = terms.Description.replaceAll("\\n", "\n");

尝试使用以下代码添加链接,但它在网页中显示为带有标记的文本。

let res = "www.google.com".link("https://www.google.com");
    desc = desc.replace("www.google.com", res);

另外我想突出显示 json 文件中的一些单词并将其显示给 UI。

谁能帮我实现同样的目标。

标签: javascripthtmljson

解决方案


推荐阅读