我目前正在使用PubleiCMS开发一个应用程序,它使用Handlebar。我正在位置. hbs
文件中创建一个Vue应用程序。我正在使用Handlebar从CMS中检索一个长字符串来创建一个JSON对象。
{{#getPostsByTags 30 "jobs" " "}}
jobsData.push(
{
"title": "{{ title }}",
"url": "{{ url }}",
"mainTag": "{{ mainTag.name }}",
"description": "{{ mainTag.description }}"
}
)
{{/getPostsByTags}}
{{main Tag.描述}}
获取存储在CMS中的文本,并在控制台中抛出错误。
未终止的字符串字面量
我可以从第45行看到可能有新行或字符抛出错误。在这一行,我可以看到字符串如下。
当将Handlebar传递给描述:
值时,如何清理或删除Handlebar中不需要的字符?我尝试过的一件事是使用JSON. stringify没有成功。
"description": "JSON.stringify({{ mainTag.description }})"
[了解更多]
我该如何处理该字符串?或者我必须从CMS修复这个问题吗?我只使用存储文本
<script>
let jobsData = [];
{{#getPostsByTags 30 "jobs" " "}}
jobsData.push(
{
"title": "{{ title }}",
"url": "{{ url }}",
"mainTag": "{{ mainTag.name }}",
"description": "{{ mainTag.description }}"
}
)
{{/getPostsByTags}}
window.onload = function () {
var app = new Vue({
delimiters: ['${', '}'],
el: '#app',
data: {
jobs: jobsData
},
computed: {
sectionTitlesWithJobs: function () {
let tags = [];
this.jobs.forEach(job=> {
tags.push(job.mainTag)
})
tags = tags.filter((a, b) => tags.indexOf(a) === b)
return tags.sort();
}
}
});
}
</script>
这就是有问题的字符串的样子:
"<p>The Product team conducts user research, creates user experience, and works closely with the internal and vendor technology teams to prototype, develop, and maintain evolving digital tools. The team also leads outreach, training and customer service for the </a href="https://www1.nyc.gov/site/opportunity/portfolio/products.page">products in its portfolio</a>. The public-facing products include <a href="https://access.nyc.gov/">ACCESS NYC</a>,
<a href "https://growingupnyc.cityofnewyork.us/">Growing Up NYC</a>, and <a href="https://growingupnyc.cityofnewyork.us/generationnyc/">Generation NYC</a> and their related APIs.</p><p>The Product team works closely integrated with other NYC Opportunity teams, including the development, design, and data teams. It also engages with other program and technology staff across City government. The team helps NYC Opportunity and our agency partners translate anti-poverty program and policy goals into digital strategies. The team also helps define how the City of New York uses modern, agile and user-centric approach to technology products, including offering product management best practices. Working as part of the team is an opportunity to continue to build a model for in-house product development and serve as national leader in digital government innovation.</p>"
这将删除新行字符:
mainTag.description.split('\n').join('')