The script part of the HTML statement in the template component, how to reference the data from the previous node

Hello, I built a template component and wrote the HTML content for generating the table, but in the script section, I couldn't reference the data from the previous node. Once I add a reference, the HTML page has no content to display. How Do I fix the previous node payload reference?

Output a payload at the preceding node:

[{“Msg”: “Item 1 point”, “Shuliang”: “1”, “Jine”: “1”} , {“Msg”: “Meat bun”, “Shuliang”: “1”, “Jine”: “2”}]

template Content:


<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <title>数据表格</title>
    <style>
        table {
            width: 50%;
            border-collapse: collapse;
            margin: 20px auto;
        }

        th,
        td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: center;
        }

        th {
            background-color: #f2f2f2;
        }
    </style>
</head>

<body>
    <table>
        <thead>
            <tr>
                <th>物品名称</th>
                <th>数量</th>
                <th>金额</th>
            </tr>
        </thead>
        <tbody>
            <!-- 数据行将在这里插入 -->
        </tbody>
    </table>

    <script>
        var data = [{"msg":"物品1点","shuliang":"1","jine":"1"},{"msg":"肉夹馍","shuliang":"1","jine":"2"}];

       **// var data =  {{payload.gouhuodanwei}};**
**      //Once I changed to this command, there was nothing to show on my table page**


        var tbody = document.querySelector('tbody');
        var  oo = 0;

     

        data.forEach(item => {
            const tr = document.createElement('tr');
            tr.innerHTML = `
                <td>${item.msg}</td>
                <td>${item.shuliang}</td>
                <td>${item.jine}</td>
            `;
            tbody.appendChild(tr);
        });
    </script>
</body>

</html>


Change the template to be a mustache template

You can then use mustache syntax inside your template, e.g. {{ Msg }} & {{ Shuliang }} ... etc and with that you can reference the data in the msg object.

Oh I see that you're already using mustache, so perhaps you're not using mustache template.

“Mustache Template” is the setting I use now

Is the payload property definitely in the msg? Use a debug before to confirm it is present and correct.

Also, as per built in docs, try using {{{ xxx }}} triple curly braces (that tells the node not to escape content)

Also, add a debug node after the template to see how your data is being rendered!

  1. I used the format {{{ XX }}} , and it still has no effect
  2. The output from a node on the template I have the debug node to make sure that the data is delivered to the template

And does it look right? Show us!

Please check if I have any mistakes

this is another picture。

You need to add the debug AFTER the template so we can see the results of the mustache rendering.

could you perhaps provide a copy of the flow your using?


I've found the problem because the payload that came in has a format error. Thank you

I've found the problem because the payload that came in has a format error. Thank you