zoukankan      html  css  js  c++  java
  • thymeleaf设置网页脚本里面的值

    thymeleaf修改javascript中的值, 下面示例为修改Fields的值

    前端使用layui配置表格字段, 字段不固定, 由后端决定.

    <script th:inline="javascript">
        var fields = eval([[${Fields}]]);
    </script>
    <script>
    layui.use(["table"], function () {
      var table = layui.table;
        table.render({
            elem: "#demo",
            id: "demo",
            url: "/getdata",
        
            cols:[fields]
        });
    });
    </script>

    后端java代码中设置Fields的值

            model.addAttribute("Fields", "[{ type: "checkbox",  120 },{ field: "id", title: "编号", align: "center", sort: true },{ field: "itemid", title: "物品", align: "center" },{ title: "操作", align: "center", fixed: "right", toolbar: "#barDemo",  300 }]");

    前端页面html中Fields为:

        var fields = eval("[{ type: "checkbox",  120 },{ field: "id", title: "u7F16u53F7", align: "center", sort: true },{ field: "itemid", title: "u7269u54C1", align: "center" },{ title: "u64CDu4F5C", align: "center", fixed: "right", toolbar: "#barDemo",  300 }]");

    thymeleaf中替换脚本值可以使用[[${变量名}]], 但转到前端为字符串, 可以使用eval再转换为js变量

  • 相关阅读:
    函数与宏定义实验报告
    C语言作业3
    循环结构课后反思
    C语言作业2
    C程序设计实验报告
    百分制成绩五级分制输出--二次作业
    第九章 结构体与共用体
    第八章 指针实验
    第七章 数组实验
    第六章 函数和宏定义实验(2)
  • 原文地址:https://www.cnblogs.com/barrysgy/p/14252581.html
Copyright © 2011-2022 走看看