我有使用$ .ajax從db來的表數據。數據不是正確的。有人可以修復代碼嗎?JQuery模板填充表問題。需要幫助
這是JavaScript文件
var ReloadGrid = (function(){
$.getJSON("/HeaderMenu/GetHeaderGrid", function(data) {
$("#gridTemplate").tmpl(data).appendTo("#mytemp");
});
});
下面是MVC3剃刀頁。問題是「mytemp」沒有填充,而是在返回3行的標題頂部顯示列。 num ++不工作不知道在哪裏初始化它需要作爲櫃檯。
<script id="gridTemplate" type="text/x-jquery-tmpl">
<tr class="gridRow">
<td class="numberingTd">
var num = 1;
num = 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>
<td class="cellTd ">${Active}</td>
</tr>
</script>
<div class="gridDiv">
<table class="gridTable" cellspacing="0" cellpadding="0">
<tr class="gridTitleRow">
<td class="numberingTd width36"> </td>
<td class="iconLink width60">Sort Order</td>
<td class="iconLink widthAuto">Display Name</td>
<td class="iconLink widthAuto">Url Name</td>
<td class="iconLink widthAuto">Active</td>
</tr>
<span id="mytemp" ></span>
</table>
</div>
計數器應該這樣做,究竟是什麼?你實際上並沒有在任何地方使用它,只是聲明,初始化,立即增加它,然後將它分配給它自己(這當然不是正確的做法)。 – 2011-06-12 19:14:47
@Matt Ball,其實我只是在測試它。我需要櫃檯而不是其價值來使物品獨一無二。我很抱歉在發佈之前沒有清理過代碼。 – Pirzada 2011-06-12 19:40:33
模板應該不包含任何邏輯 - 儘可能讓它們啞。將數字放入傳遞給'.tmpl()'的數據中。 – 2011-06-12 19:42:47