首页 > 解决方案 > 如何在 javascript 函数中访问 Mustache 文件 [更新]?

问题描述

我有一些数据存储在 java 代码中的 ArrayList 中,我正在使用 Mustache 在我的 HTML 网页上显示 myArray 的结果。

myIndex.html 文件:

<html>
<head>
    <script>
        var plotMapHidden = true;
        {{{myArray}}}
    </script>
</head>
<body>
<div class="card-body">
    {{#myArray}}
    <strong> {{.}} </strong> <br>
    {{/myArray}}
</div>
<script >
    // I want to access {{myArray}} data here as well like var newArray = {{myArray}}
</script>
</body>
</html>

有什么方法可以访问脚本中的 Mustache 数据,如上所示?

HTML 成功输出了 div 部分([1,2,...,100])。我想重用部分中的 myArray 数据以及执行其他 javascript 函数。谢谢

标签: javascriptmustache

解决方案


推荐阅读