【发布时间】:2010-06-21 20:23:21
【问题描述】:
我正在尝试使用动态构建信息构建一个表。
我的想法是将 DivA 放在每个单元格中,然后将 DivB 和 DivC 放在 DivA 标记中(DivB 显示“加载”img,DivC 显示内容)。然后,我希望使用对我的 ASP.Net MVC Web 应用程序的 json 调用来更新单元格。到目前为止听起来很疯狂吗?!
<div class="divA">
<h2>
Stuff</h2>
<div class="divB">
<img src="Images/ajax-loader.gif" />
<span>Loading</span>
</div>
<div class="divC">
</div>
</div>
使用此代码,我认为我可以激活我的方法并处理回调?
$(document).ready(
function()
{
$("div.divA").each(
function(i)
{
updateCellDivs($(this));
}
);
}
)
但是...我在尝试在下面的“加载”上调用 show 时遇到异常 - 调用 fadeIn 相同的东西。 “加载”对象的类型是 disphtmldivelement - 但 DivA 也是如此。
我不知所措 - 我做错了什么?!
感谢任何cmets,
安德斯,丹麦。
updateCellDivs = function(DivA)
{
jQuery.getJSON("/Home/GetSomething",
function(json)
{
mainDiv = DivA[0];
divs = $("div", mainDiv);
loading = divs[0];
contents = divs[1];
// Abort if there is no data to update.
if (contents.length==0)
{
return;
}
loading.show(1000);
//contents.fadeOut(1000);
// If no response was given, the data was not yet available.
// Ask again in two seconds!
if (json == "")
{
setTimeout(updateCellDivs, 2*1000);
return;
}
DivA.fadeOut(1000);
//loading.fadeOut(1000);
DivA.fadeIn(1000);
});
}
【问题讨论】: