English 中文(简体)
无法打印 jquery 模板数据
原标题:unable to print the jquery template data

我正用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 复选框被显示, 但没有文本 。

任何尸体能帮我找出变化之处吗?

问题回答

问题在于 Jsp 中写入的代码, Jsp 使用 JSTL 标签库,而 JSP 则使用 JSTL 标签库, $是特殊字符, 由 jstl 解释, 数据在 jsp 页面中被输入 。

我们有两个解决办法:

  1. append special character this way ${ $ }{id}
  2. we can also set <%@ page isELIgnored="true"%>

谢谢 谢谢





相关问题
Making jquery tmpl without a lot of extra script tags

I ve been reading about the jQuery template plugin http://api.jquery.com/tmpl/ as a means of binding data to markup. All the examples seem to show that you define the template in a script new script ...

How do I render a jQuery.tmpl Template to a String?

The documentation for jquery.tmpl uses .appendTo to insert the template into the DOM during the rendering process: $.tmpl( myTemplate, myData ).appendTo( "#target" ); I am attempting to convert an ...

how to tell if a property exists and is false

I am having a hard time determining if data passed into the jquery template exists and is false without getting errors. This is what I am using to test <html> <head> <title>jQuery ...

热门标签