Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 使用JQuery模板生成的网格需要使用Ajax重置,但不起作用_Asp.net Mvc 3_Jquery_Jquery Templates - Fatal编程技术网

Asp.net mvc 3 使用JQuery模板生成的网格需要使用Ajax重置,但不起作用

Asp.net mvc 3 使用JQuery模板生成的网格需要使用Ajax重置,但不起作用,asp.net-mvc-3,jquery,jquery-templates,Asp.net Mvc 3,Jquery,Jquery Templates,有时工作,有时不工作 我试图在添加或删除记录后,通过Ajax借助JQuery模板生成网格。在js文件中 $('.gridRow').remove(); 它不能正常工作有人告诉我如何重置网格以再次填充它。下面是代码 JS文件 var ReloadGrid = (function(){ $.getJSON("/HeaderMenu/GetHeaderGrid", function(data) { $('.gridRow').remove();

有时工作,有时不工作

我试图在添加或删除记录后,通过Ajax借助JQuery模板生成网格。在js文件中

$('.gridRow').remove();
它不能正常工作有人告诉我如何重置网格以再次填充它。下面是代码

JS文件

var ReloadGrid = (function(){
            $.getJSON("/HeaderMenu/GetHeaderGrid", function(data) {
                $('.gridRow').remove();
                (data.length <= 0) ? $("#gridBtn").hide() : $("#gridBtn").show();
                for (var i=0; i<data.length; i++) { data[i].num = i+1; }
                $('#gridTemplate').tmpl(data).appendTo('table.gridTable > tbody');
            });
 });
<script id="gridTemplate" type="text/x-jquery-tmpl">
    <tr class="gridRow">
        <td class="cellTd ">
            <input type="checkbox" id="deleteCb" />
            <input type="hidden" id="Id_ + ${num}" class="idField" value="${Id}" />
        </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}</td>
        <td class="cellTd ">
            <input type="checkbox" id="activeCb" {{if Active}} checked{{/if}} />
        </td>
    </tr>

</script>

<div class="gridDiv">
<table class="gridTable" cellspacing="0" cellpadding="0">
    <tbody>
        <tr class="gridTitleRow">
            <td class="iconLink width36">Delete</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>
    </tbody>
</table>
</div>
var ReloadGrid=(函数(){
$.getJSON(“/HeaderMenu/GetHeaderGrid”,函数(数据){
$('.gridRow').remove();

(data.length我通常清空包装而不是行

$('table.gridTable > tbody').empty();
但要使其起作用,您必须将表更改为使用
thead

<table class="gridTable" cellspacing="0" cellpadding="0">
    <thead>
        <tr class="gridTitleRow">
            <th class="iconLink width36">Delete</th>
            <th class="iconLink width60">Sort Order</th>
            <th class="iconLink widthAuto">Display Name</th>
            <th class="iconLink widthAuto">Url Name</th>
            <th class="iconLink widthAuto">Active</th>
        </tr>
    <thead>
    <tbody>
    </tbody>
</table>

删除
排序顺序
显示名称
Url名称
活跃的