【问题标题】:unable to print the jquery template data无法打印 jquery 模板数据
【发布时间】:2012-05-25 00:54:31
【问题描述】:

我正在使用 json 来获取请求。我的响应对象格式是:

[
{"id":3,"name":"Zuned Ahmed"},
{"id":4,"name":"ZunedTWO"},
{"id":7,"name":"TORCH"}
]

ajax 调用是:

$.ajax( {
                type : 'GET',
                url : URL,
                async : false,
                dataType : "json",
                success : function(data) {
                    $("#product_data_div").html($("#product_template").tmpl(data));
                }

            });

模板代码为:

<div id="product_data_div">
                <script id="product_template" type="text/x-jquery-tmpl">
                    <input type="checkbox" id="product_${id}" name="" value="${id}" class="margin-top10">
                    <label for="product_${id}" class="margin-top10">${name}</label>
                    <div class="clear"></div>
                </script>
                </div>

数据未显示,3 个复选框显示但没有文本。

谁能帮我找出变化。

【问题讨论】:

  • 谁能提供一些我哪里出错的建议。提前致谢。

标签: jquery-templates


【解决方案1】:

问题是用jsp编写的代码,它使用的是JSTL标签库,对于JSP,'$'是特殊字符,它由jstl解释,数据填充到jsp页面上。

为了解决这个问题,我们有 2 个解决方案:

  1. 以这种方式附加特殊字符 ${'$'}{id}
  2. 我们也可以设置

谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-23
    • 2020-07-26
    • 2013-10-20
    • 1970-01-01
    • 1970-01-01
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多