我有一个Telerik ListView,我从服务器端绑定它。这个html如下所示,
<asp:Panel ID="Panel1" runat="server">
<div id="divOuterListView2" class="wrap-list">
<telerik:RadListView ID="RadListView2" runat="server" ItemPlaceholderID="DataItemHolder">
<LayoutTemplate>
<asp:Panel ID="DataItemHolder" runat="server">
</asp:Panel>
</LayoutTemplate>
<EmptyDataTemplate>
<div class="notif no-data">
<h1>
Sorry !</h2>
<h2>
No Data found.</h3>
</div>
</EmptyDataTemplate>
<ItemTemplate>
<div class="data-item">
<div class="content">
<p id="p_Name" class="rs">
<asp:Label ID="lblName" Width="100%" runat="server" Text='<%#Eval("Name") %>' />
</p>
<p id="p_Description" class="rs coupon-desc">
<asp:Label ID="lblDescription" Width="100%" runat="server" Text='<%#Eval("Description") %>' />
</p>
</div>
</div>
</ItemTemplate>
</telerik:RadListView>
</div>
</asp:Panel>
最初在ListView中显示10条记录。当用户向下滚动并到达底部时,Jquery在ListView下面还会添加10条记录,
$(document).ready(function () {
var pageIndex = 1;
var pageCount;
var canRun = true;
$(window).scroll(function () {
if (canRun == true) {
if ($(window).scrollTop() + $(window).height() > ($('.mod-footer').position().top + 30)) {
canRun = false;
sendData();
}
}
});
function sendData() {
pageIndex++;
if (pageIndex == 2 || pageIndex <= pageCount) {
$("#loader").show();
$.ajax(
{
type: "POST",
url: "Records.aspx/GetRecord",
data: '{pageIndex: ' + pageIndex + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
async: "true",
cache: "false",
success: OnSuccess,
failure: function (response) {
alert("Failure: " + response.d);
$("#loader").hide();
canRun = true;
},
error: function (response) {
alert("Error: " + response.d);
$("#loader").hide();
canRun = true;
}
});
}
}
function OnSuccess(response) {
var xmlDoc = $.parseXML(response.d);
var xml = $(xmlDoc);
pageCount = parseInt(xml.find("PageCount").eq(0).find("PageCount").text());
var deals = xml.find("Deals");
deals.each(function () {
var deal = $(this);
var dataDiv = $("#divOuterListView2 div").eq(0).clone(true);
$("#p_Name", dataDiv).html(deal.find("Name").text());
$("#p_Description", dataDiv).html(deal.find("Description").text());
});
$("#loader").hide();
canRun = true;
}
});
现在我有了一个DropDownList for Regions。在DropDownList的SelectedIndexChange上,我根据Region异步重新加载数据。
现在,ListView中的数据已成功更改和更新,但Jquery附加的数据仍然存在。我想在异步回发上删除该数据。
在启动Ajax请求时,我调用了一个Javascript函数,
function RequestStart(sender, args) {
$("#divOuterListView2 div").remove();
}
现在第一次更改DropDownList索引时,将显示空白页面,并且不显示任何数据。但第二次DropDownList被更改,那么数据加载就好了。我在这里缺少什么?请指导我?