在车把的脚本标签中设置数组属性

时间:2020-02-06 09:49:57

标签: html node.js express dom express-handlebars

我在脚本标记中提出了ajax请求,该请求返回了一个数组。我想遍历html中的此数组,但是无法遍历脚本中的对象。 这是我的代码:

<body style="margin: 0; overflow-x: hidden;">
    <input type="hidden" id="url" value={{url}} />
    {{#each listOfNumbers}}
    <h1>{{this}}</h1>
    {{/each}}
    <footer>
        <p>Copyright. All rights reserved 2020</p>
    </footer>
</body>
<script>
    $(function () {
        const token = localStorage.getItem("token")
        const url = document.getElementById("url").value
        $.ajax({
            url: url + '/charge-log',
            beforeSend: xhr => { xhr.setRequestHeader('Authorization', token); },
            type: "GET",
            success: res => {
                console.log(res)
                $("body").listOfNumbers = ["1", "2"]
            },
            error: () => { location.href = '/' }
        });
    });
</script>

0 个答案:

没有答案
相关问题