【问题标题】:jsReports assets nodejsjsReports 资产 nodejs
【发布时间】:2021-11-07 07:30:38
【问题描述】:

我正在尝试将 css 样式表作为资产添加到 jsReport 报告中。

  jsreport.render({
    template: {
      content: `

     
      <html>
      <link rel="stylesheet" type="text/css" href="/css/style.css">
          <head>
              <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
              <style>
                  {#asset /css/style.css}
              </style>
          </head>
          <body>
             ...
          </body>
      </html>

      `,
      
      engine: 'handlebars',
      recipe: 'html',
      assets: {
        allowedFiles: "static/**.js",
        publicAccessEnabled: true,
        searchOnDiskIfNotFoundInStore: true,
      },
    },
    data: newCart
  }).then((out) => {
    out.stream.pipe(res);
  }).catch((e) => {
    res.end(e.message);
  });

当我尝试加载资产时,问题出在标签内。 关于如何做到这一点的任何想法? 提前致谢! :)

【问题讨论】:

    标签: javascript node.js assets jsreport


    【解决方案1】:

    在 jsreportonline.net 中,我总是将资产放在第一行,所以也许像下面这样可以工作。

        template: {
          content: `
    
          <style>
              {#asset /css/style.css @encoding=utf8}
          </style>     
          <html>
          <link rel="stylesheet" type="text/css" href="/css/style.css">
              <head>
                  <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
              </head>
              <body>
                 ...
              </body>
          </html>
    
          `,
          
          engine: 'handlebars',
          recipe: 'html',
          assets: {
            allowedFiles: "static/**.js",
            publicAccessEnabled: true,
            searchOnDiskIfNotFoundInStore: true,
          },
        },
        data: newCart
      }).then((out) => {
        out.stream.pipe(res);
      }).catch((e) => {
        res.end(e.message);
      });`
    

    【讨论】:

      【解决方案2】:

      我“解决”了直接在标签中粘贴 css 的问题,因为问题在于 #asset 的导入。

      不是最好的解决方案,但它有效:)

      【讨论】:

      • 其他解决方案无效?另外,如您在 2 天多前提出的问题,您可以接受自己的回答
      猜你喜欢
      • 2013-05-13
      • 1970-01-01
      • 2020-01-16
      • 1970-01-01
      • 2012-06-16
      • 2015-12-04
      • 2013-01-10
      • 2022-06-10
      • 1970-01-01
      相关资源
      最近更新 更多