Javascript变量替换(CK编辑器)
如何用动态值替换Javascript变量替换(CK编辑器),javascript,node.js,reactjs,Javascript,Node.js,Reactjs,如何用动态值替换{$name},{$city},{$country}。动态值为json格式。 我的要求:最初只有用户使用CKEditor创建布局设计。然后用户将上载CSV文件。CSV中的所有数据将替换{$value}。这就是概念 <p>This is the <strong>default </strong>CKEditor installation.{$name} Source editing is provided by the Source Editin
{$name}
,{$city}
,{$country}
。动态值为json格式。
我的要求:最初只有用户使用CKEditor创建布局设计。然后用户将上载CSV文件。CSV中的所有数据将替换{$value}
。这就是概念
<p>This is the <strong>default </strong>CKEditor installation.{$name} Source editing is provided by the Source Editing Area</a> 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>
你可以用
const arr=[
{名称:'foo',城市:'cityFoo',国家:'countryFoo'},
{名称:'bar',城市:'cityBar',国家:'countryBar'}
]
console.log(arr.map(
({姓名、城市、国家})=>
` 这是默认的CKEditor安装。${name}源代码编辑由源代码编辑区插件提供。按照下面的${city}步骤尝试${country}`
))
正如op所说,他们正在从数据库中获取模板。我假设它是一个字符串。
您可以使用它来创建一个模板文本
const template=“这是默认的CKEditor安装。${name}源代码编辑由源代码编辑区插件提供。按照下面的${city}步骤尝试${country}:- 单击源代码按钮以显示此tex${website}${email}的HTML源代码在源代码编辑区域。
- 再次单击源代码按钮返回所见即所得视图。
名字:
“
常量替换=[{
“姓名”:“Lijo”,
“城市”:“邦劳尔”,
“国家”:“印度”,
“网站”:“,
“电子邮件”:”
},
{
“名称”:“Thoams”,
“城市”:“钦奈”,
“国家”:“印度”,
“网站”:“,
“电子邮件”:”
}
]
const inset=新函数('name'、'city'、'country'、'website'、'email'、'return`'+模板+')
const filledIn=replacements.map({name,city,country,website,email})=>inset(name,city,country,website,email))
console.log(filledIn)
对于多个用户,JSON会创建多行文本吗?这如何与存储在数据库中的模板一起工作<代码>评估?
[
{
"name": "Lijo",
"city": "Banglaore",
"country": "India",
"website": "",
"email": ""
},
{
"name": "Thoams",
"city": "Chennai",
"country": "India",
"website": "",
"email": ""
},
{
"name": "Maria",
"city": "Mumbai",
"country": "India",
"website": "",
"email": ""
},
{
"name": "Dravid",
"city": "New York",
"country": "US",
"website": "",
"email": ""
},
{
"name": "Sachin",
"city": "London",
"country": "UK",
"website": "",
"email": ""
},
{
"name": "John",
"city": "Canbera",
"country": "AUS",
"website": "",
"email": ""
}
]