用Node.js后端中的数组对象替换变量

问题描述 投票:0回答:1

数据库中的模板

<p>This is the <strong>default </strong>CKEditor installation.{$name} Source editing is provided by the Source Editing Area</a>&nbsp;plugin.</p><p>Follow the{$city}steps below to try it{$country}out:</p><ul><li>Click the <strong>Source </strong>button to display the HTML source of this tex {$website} {$email}in the source editing area.</li><li>Click the <strong>Source </strong>button again to return to the WYSIWYG view.</li></ul><form>First name:<br>

以上我保存在数据库中的HTML代码。所有变量($ name,$ city,$ country,$ website,$ email)应替换为以下对象,并创建新的html模板并保存到数据库。

[
        {
            "name": "Lijo",
            "city": "Banglaore",
            "country": "India",
            "website": "",
            "email": ""
        },
        {
            "name": "Thoams",
            "city": "Chennai",
            "country": "India",
            "website": "",
            "email": ""
        }]
javascript arrays node.js
1个回答
0
投票

这似乎是处理这种事情的一种奇怪的方法,但是无论什么都会浮上水面。您可以使用replace()查找模板中的占位符并将其替换为对象中的值。

© www.soinside.com 2019 - 2024. All rights reserved.