【问题标题】:jQuery Ajax passing key/value success retrieval to templatejQuery Ajax 将键/值成功检索传递给模板
【发布时间】:2011-06-12 21:44:55
【问题描述】:

我无法完成这项工作。我想要的只是将 num 计数器值传递给模板。

var ReloadGrid = (function() {
    $.getJSON("/HeaderMenu/GetHeaderGrid", function(data) {
        data.num = $('#mytemp tr').length + 1; // Not working
        $("#gridTemplate").tmpl(data).appendTo("#mytemp");
    });
 });

模板:

<script id="gridTemplate" type="text/x-jquery-tmpl">
    <tr class="gridRow">
        <td class="numberingTd">
            ${num}          
        </td>
        <td class="cellTd">
            <input id="index" name="index" class="numberField" type="text" value="${IndexOrder}" />
        </td>
        <td class="cellTd">${DisplayName}</td>
        <td class="cellTd ">${UrlName} Us</td>
    </tr>
</script>

还有如何在模板中添加数字,例如${num} + 1

【问题讨论】:

    标签: jquery jquery-templates


    【解决方案1】:

    使用 javascript 控制台(或您拥有的任何浏览器中的等效控制台)来获取有意义的错误

    您是否尝试过简单地alert($('#mytemp tr').length) 来查看是否可以找到该值?

    【讨论】:

    • 返回值 1。我正在使用 firefox 调试器。我在另一边也没有看到 1。
    • 我已经编辑了我的问题并添加了网格模板给你看。
    猜你喜欢
    • 2014-12-18
    • 1970-01-01
    • 2013-11-17
    • 1970-01-01
    • 2016-09-09
    • 2020-06-04
    • 2011-01-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多