【问题标题】:How to connect loop data to pdfgeneratorapi with wix corvid?如何使用 wix corvid 将循环数据连接到 pdfgeneratorapi?
【发布时间】:2020-08-14 11:26:42
【问题描述】:

我正在使用 https://pdfgeneratorapi.com/ 生成 PDF。

现在我可以使用此代码一一显示数据。谁能给我建议如何使用循环或任何其他方式显示所有数据? 下面的照片显示了我来自 pdfgenerator 的模板。

这是我用来生成 PDF 的代码

    let communicationWay1=[
    {0:"dim"},
    {1:"kal"}
    ];
    let cstomerExpence1=[
    {0:"dim"}, 
    {1:"kal"}
    ];
   let title="test";
   let names="test";
   let phone="test";
   let email="test";
let maritalStatus="test";
let city="test";
let other="test";

 const result = await wixData.query(collection)
 .eq('main_user_email', $w('#mainE').text)
         .find()
    .then( (results) => {
 if (results.totalCount>0) {
                    count=1;
 // title=results.items[1].title;
                        names=results.items[0].names;
                        email=results.items[0].emial;
                        phone=results.items[0].phone;
                        maritalStatus=results.items[0].maritalStatus;
                        city=results.items[0].city;
                        other=results.items[0].cousterExpenses_other;                       
                        title=results.items[0].title;
 
                        communicationWay=results.items[0].communicationWay;
                        cstomerExpence=results.items[0].cstomerExpence;

                }
 if (results.totalCount>1) {              
                        names1=results.items[1].names;
                        email1=results.items[1].emial;
                        phone1=results.items[1].phone;
                        maritalStatus1=results.items[1].maritalStatus;
                        city1=results.items[1].city;
                        other1=results.items[1].cousterExpenses_other;                      
                        title1=results.items[1].title;
                        communicationWay1=results.items[1].communicationWay;
                        cstomerExpence1=results.items[1].cstomerExpence;
                }
 
    } )
    .catch( (err) => {
      console.log(err);
    } );
 // Add your code for this event here:  
 const pdfUrl = await getPdfUrl
 ({title,names,email,phone,city,maritalStatus,other,communicationWay,cstomerExpence,title1,
  names1,email1,phone1,city1,maritalStatus1,other1,communicationWay1,cstomerExpence1   
    });
if (count===0) {    $w("#text21").show();}
else{        $w("#downloadButton").link=wixLocation.to(pdfUrl);}   

下面的代码是后端代码/JSW 代码。 我也想在新标签中打开pdf。我知道“_blank”方法可以用来打开一个新标签。但我不知道如何用url添加它

 import PDFGeneratorAPI from 'pdf-generator-api'

const apiKey = 'MYKEY';
const apiSecret = 'MYAPISECRET';

const baseUrl = 'https://us1.pdfgeneratorapi.com/api/v3/';
const workspace = "HELLO@gmail.com";
const templateID = "MYTEMPLATEID";

let Client = new PDFGeneratorAPI(apiKey, apiSecret)
Client.setBaseUrl(baseUrl)
Client.setWorkspace(workspace)

export async function getPdfUrl(data) {
 const {response} = await Client.output(templateID, data, undefined, undefined, {output: 'url'})
 return response
}

【问题讨论】:

  • 让我们先从您的模板开始:我认为您需要将这些行包装在模板编辑器中的“容器”项中。然后,您可以为数据集合中的每个项目重复每一行。查看他们网站上的“发票”模板示例,了解他们如何处理订单项。这将允许您将数据作为数组传递给 API。

标签: javascript api rest pdf-generation velo


【解决方案1】:

只需将其放入带有布尔条件的 while 循环中即可。

您可以创建一个变量,例如allShowed,并将其值设置为False。之后,创建另一个变量,例如numberOfDataToShow,并将其设置为要显示的元素数。然后创建一个计数器countShowed,初始化为0作为它的值。

现在创建一个while循环:当allShowed的值为False时,你循环(并添加数据)。 每次显示一段数据时,都会增加 countShowed 的值(并将其设置为继续添加/显示数据)。当countShowed 的值与numberOfDataToShow 完全相同时,将allShowed 设置为True。循环将中断并显示您的所有数据。

【讨论】:

    【解决方案2】:

    您需要使用 PDF Generator API 中的 ContainerTable 组件来迭代项目列表。正如@JustCallMeA 所说,您需要发送一系列项目。 PDF Generator API 现在有一个官方的 Wix Velo(以前是 Corvid)教程和一个演示页面:https://support.pdfgeneratorapi.com/en/article/how-to-integrate-with-wix-velo-13s8135

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-20
      • 1970-01-01
      • 1970-01-01
      • 2019-06-21
      • 1970-01-01
      相关资源
      最近更新 更多