2017-09-26 67 views
0

我正在尝试使用jsreport-assetsjsreport-core。但是,我得到一个错误,当我尝试在我的模板充分利用的资产,就像这样:如何配置jsreport资产

<img class="logo" src="{#asset myimage.png @encoding=dataURI}" /> 

错误:未找到

我感到困惑在哪里存储我的资产文件,以及如何资产myimage.png配置jsreport-core和/或jsreport-assets以利用这些资产。

回答

2

默认情况下jsreport资产扩展仅在本地“数据库”中搜索。您需要启用搜索本地文件,请参阅docs

const jsreport = require('jsreport-core')() 
jsreport.use(require('jsreport-assets')({ 
    searchOnDiskIfNotFoundInStore: true, 
    allowedFiles: '**/*.*' 
})) 

jsreport.init().then(async() => { 
    const res = await jsreport.render({ 
     template: { 
      content: '{#asset foo.txt}', 
      engine: 'none', 
      recipe: 'html' 
     } 
    }) 

    console.log(res.content.toString()) 
})