提问者:小点点

车把清理字符串-SynaskError:未终止的字符串文字


我目前正在使用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>

这就是有问题的字符串的样子:

"&lt;p&gt;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 &lt;/a href&#x3D;&quot;https://www1.nyc.gov/site/opportunity/portfolio/products.page&quot;&gt;products in its portfolio&lt;/a&gt;. The public-facing products include &lt;a href&#x3D;&quot;https://access.nyc.gov/&quot;&gt;ACCESS NYC&lt;/a&gt;,
        &lt;a href &quot;https://growingupnyc.cityofnewyork.us/&quot;&gt;Growing Up NYC&lt;/a&gt;, and &lt;a href&#x3D;&quot;https://growingupnyc.cityofnewyork.us/generationnyc/&quot;&gt;Generation NYC&lt;/a&gt; and their related APIs.&lt;/p&gt;&lt;p&gt;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.&lt;/p&gt;"

共1个答案

匿名用户

这将删除新行字符:

mainTag.description.split('\n').join('')