(Html)正在将单引号转换为双引号,节点如何快速发送字符串?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (223)

我试图以html的形式发送这个字符串。字符串存储在var,并使用res.send(respuesta);

<div data-nanogallery2='{
        "itemsBaseURL": "http://nanogallery2.nanostudio.org/samples/",
        "thumbnailWidth": "auto",
        "thumbnailBorderVertical": 0,
        "thumbnailBorderHorizontal": 0,
        "colorScheme": {
          "thumbnail": {
            "background": "rgba(0,0,0,0)"
          }
        },
        "thumbnailDisplayTransition": "flipDown",
        "thumbnailDisplayTransitionDuration": 750,
        "thumbnailDisplayInterval": 250,
        "thumbnailLabel": {
          "display": false
        },
        "thumbnailHoverEffect2": "toolsAppear|scale120",
        "galleryDisplayMode": "pagination",
        "galleryPaginationMode": "numbers",
        "thumbnailAlignment": "center"
      }'>
      <a href="berlin1.jpg" data-ngthumb="berlin1t.jpg" data-ngdesc="">Berlin 1</a>
      <a href="berlin2.jpg" data-ngthumb="berlin2t.jpg" data-ngdesc="">Berlin 2</a>
      <a href="berlin3.jpg" data-ngthumb="berlin3t.jpg" data-ngdesc="">Berlin 3</a>

    </div>

问题是不知怎么的'自动转换为",这就扰乱了我的客户端标记。

是否有任何方法来维护'

提问于
用户回答回答于

你可以用反勾号:

`{
    "itemsBaseURL": "http://nanogallery2.nanostudio.org/samples/",
    "thumbnailWidth": "auto",
    "thumbnailBorderVertical": 0,
    "thumbnailBorderHorizontal": 0,
    "colorScheme": {
      "thumbnail": {
        "background": "rgba(0,0,0,0)"
      }
    },
    "thumbnailDisplayTransition": "flipDown",
    "thumbnailDisplayTransitionDuration": 750,
    "thumbnailDisplayInterval": 250,
    "thumbnailLabel": {
      "display": false
    },
    "thumbnailHoverEffect2": "toolsAppear|scale120",
    "galleryDisplayMode": "pagination",
    "galleryPaginationMode": "numbers",
    "thumbnailAlignment": "center"
  }`>
用户回答回答于

无法重现在字符串模板文字中测试所提供代码的缩减版本以使用节点8.9.1和表达式4.13.3形成有效的HTML文档时出现的问题。

Express Server

var express = require('express');
var app = express();
app.all("/testexpress", function( req, res, next) {
    var html = `<!DOCTYPE html><html><head><meta charset="utf-8"></head><body>
<div id="nano" data-nanogallery2='{
        "itemsBaseURL": "http://nanogallery2.example.org/samples/",
        "thumbnailWidth": "auto"}'>
     div element #nano
</div>
<script>
    var nano = document.getElementById("nano");
    console.log( "data-nanogallery2  = " + nano.dataset.nanogallery2);
</script>
</body></html>
`;
    res.send( html);
});
var server = app.listen(80, function () {
  console.log("testexpress listening on local host port 80");
});

URL

http://localhost/testexpress

当测试(在Firefox中)时,数据-Nanogallery属性在页面源中保持不变,并且属性值报告时,控制台上的单引号不像预期的那样。

控制台输出

`data-nanogallery2 = { "itemsBaseURL": "`[`http://nanogallery2.example.org/samples/`](http://nanogallery2.example.org/samples/)`", "thumbnailWidth": "auto"}`

扫码关注云+社区

领取腾讯云代金券