【问题标题】:Add anchor to javascript array for use with handlebars.js将锚点添加到 javascript 数组以与 handlebars.js 一起使用
【发布时间】:2015-05-12 01:43:18
【问题描述】:

我有很多数组存储在一个 javascript 变量中。我的一个数组的一个例子是:

{
    index: 6,
    template: 2,
    title: "Innovation Center",
    shortname: 'innov',
    projectActive: 'true',
    subtitle: "Construct",
    location: "alaska",
    x: 1304,
    y: 610,
    image1: "img/watt.jpg",
    image2: "img/image_2.jpg",
    bgImage: "img/bgImage.jpg",
    headline1: "Catapulting Ideas to Reality",
    paragraph1: "A long paragraph of text",
    headline2: "The Future Won't Wait, and Neither Will We",
    paragraph2: "This is a long paragraph of text",
    listTitle: "Innovative resources include: ",
    listItems: [
            { item: "Visual analytics" },
            { item: "Communication skills development" },
        ]
},

使用 handlebars.js 将其打印成 HTML,如下所示:

<div class="header" style="background-image: url( {{ bgImage }} );" >
          <div class="container">
            <div class="col-sm-12">
              <h1> {{ title }} </h1>
              <h4> {{ subtitle }} </h4>
            </div>
          </div>
        </div>

        <div class="container">
            <div class="row paragraph1">
              <div class="col-sm-6" >
                <div class="image1" style="background-image: url( {{image1}} );">
                </div>
              </div>
              <div class="col-sm-6">
                <h2> {{ headline1 }}</h2>
                <p> {{ paragraph1 }} </p>
              </div>
            </div>

我的问题是如何使用 html 将一些文本包装在“段落”键值中。所以我想做的是:

paragraph1: "A long <a href="google.com">paragraph</a> of text",

但这只是在页面上吐出代码。任何帮助将不胜感激。

【问题讨论】:

标签: javascript html escaping handlebars.js


【解决方案1】:

尝试使用三重存储:

{{{ paragraph1 }}}

http://handlebarsjs.com/#html-escaping

【讨论】:

    猜你喜欢
    • 2021-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-18
    • 1970-01-01
    • 2016-06-05
    • 2023-03-08
    相关资源
    最近更新 更多