如何单独获取对象值并推入临时变量 - jsPDF-autoTable

How to get Object values alone and push into temporary variable - jsPDF-autoTable

以下是我从后端获得的示例响应。

let data = [
{
    "thisIsTheResponseFromBackEnd": [
    {
        "Col Header 1": "AAA, AAA",
        "Col Header 2": "BCD",
        "Col Header 3": "dummy data 1",
    },
    {
        "Col Header 1": "BBB, BBB",
        "Col Header 2": "BCD",
        "Col Header 3": "dummy data 1",
    },
    {
        "Col Header 1": "Hello,world",
        "Col Header 2": "BCD",
        "Col Header 3": "dummy data 1",

    }]
}]

我正在尝试将动态数据推送到 jspdf autoTable。我用 header: Object.keys(data[0]) //as column

但如果尝试推送对象的值,它 returns 仅 [object, Object]

我尝试了以下可能的方法将数据推送到 jspdfatuoTable 的主体中。但未能通过以下方法。

/*  Object.keys( data ).forEach( key => {
        console.log( data[key] );
        const temp = [data[key]];
        rows.push(temp);
         console.log('body ?', rows);
    }); */

/* Object.keys(data).forEach(function (prop) {
        const temp = [data[prop]];
        rows.push(temp);
    }); */

for (let [key, value] of Object.entries(data)) {   
    const temp = [data.value];
    rows.push(temp);
    console.log('body ?', rows);
}

有人可以帮我解决这个问题吗?

谢谢

Header: Object.keys(data[0])[0]

Body: data.map(x => Object.values(x))

通过 For 循环你也可以轻松解决这个问题你所要做的就是正确访问你的对象。

    let data = [
    {
        "thisIsTheResponseFromBackEnd": [
        {
            "Col Header 1": "AAA, AAA",
            "Col Header 2": "BCD",
            "Col Header 3": "dummy data 1",
        },
        {
            "Col Header 1": "BBB, BBB",
            "Col Header 2": "BCD",
            "Col Header 3": "dummy data 1",
        },
        {
            "Col Header 1": "Hello,world",
            "Col Header 2": "BCD",
            "Col Header 3": "dummy data 1",

        }]
    }]


    var res = data[0].thisIsTheResponseFromBackEnd
    for (var i = 0; i < res.length; i++) {
      console.log(res[i])
    }

希望对你有帮助