嗨,我正在使用 JQuery 选项卡 http://jqueryui.com/demos/tabs /
搜索结果从我的服务器返回,每一行可能有自己的选项卡,具体取决于搜索结果。如果用户单击排序选项,则搜索结果会发生变化,包括返回的每行中可能有或没有选项卡的选项卡。在上面的示例中,您可以看到返回了 2 条记录,并且顶部记录有名为“其他视频”的选项卡。
我已经成功地从服务器检索结果集,并且模板正确构建,但是我无法触发 .tabs() 函数?有谁有使用选项卡的经验并且知道如何启动我的 tabs() 函数?
下面是我在返回 json 结果集后用于动态加载模板的代码:
$(".searchBox").fadeOut("fast", function () {
$(this).html("").fadeIn("fast", function () {
$("#searchTemplate").tmpl(json.Data.SearchResults.Results).appendTo(".searchBox").fadeIn("fast");
});
});
这是一个 for 循环,在加载模板并创建新的 html 选项卡后,我用它来迭代结果,以尝试获取要触发的 .tabs() 函数:
for(var i=0;i
{
if (json.Data.SearchResults.Results[i].OtherVideos.length || json.Data.SearchResults.Results[i].VideoFriends.FriendCount > 0)
{
$(document).find("div[id='tabs"+json.Data.SearchResults.Results[i].Counter+"']").tabs();
if ($(document).find("div[id='tabs"+json.Data.SearchResults.Results[i].Counter+"']").length > 0)
alert("it exists");
else
alert("it dont");
}
}
可以说警报框“它存在”成功显示,因此它正在查找模板生成的动态创建的 html 选项卡,但是选项卡本身并未由以下语句初始化:
$(document).find("div[ id='tabs"+json.Data.SearchResults.Results[i].Counter+"']").tabs();
有谁知道我在这里缺少什么来获取 .tabs 的原因或内容() 函数来触发...
我已经检查了动态内容,并使用 firebug 检查器仔细检查了 html 代码,一切都按照 id 正确的方式进行,#id 在那里等等,所以我唯一的结论是 .tabs() 函数没有触发。这是 JQuery 选项卡本身的限制吗?它不能执行这种类型的“实时”加载功能吗?我应该使用回调函数作为加载模板本身的一部分吗?
以下是在选项卡不工作的情况下调用服务器后返回的内容的图片:
Hi I'm using JQuery tabs http://jqueryui.com/demos/tabs/
with search results being returned from my server with each row potentially having its own tabs depending on the search results. If the user clicks on the sorting options then the search results change including the tabs within each row returned which may or may not have tabs. In the example above you can see there are 2 records returned and the top record has tabs called Other Videos.
I have been successfully able to retrieve the resultset back from the server and the template is bulding correctly, however i cannot get the .tabs() function to fire? Does anyone have any experience with using tabs and know how I can get my tabs() function to fire?
Here is the code I use to dynamically load the template after the json result set is returned:
$(".searchBox").fadeOut("fast", function () {
$(this).html("").fadeIn("fast", function () {
$("#searchTemplate").tmpl(json.Data.SearchResults.Results).appendTo(".searchBox").fadeIn("fast");
});
});
And here is a for loop that I use to iterate over the results after the template has been loaded with the new html tabs created to try and get the .tabs() function to fire:
for(var i=0;i<json.Data.SearchResults.Results.length;i++)
{
if (json.Data.SearchResults.Results[i].OtherVideos.length || json.Data.SearchResults.Results[i].VideoFriends.FriendCount > 0)
{
$(document).find("div[id='tabs"+json.Data.SearchResults.Results[i].Counter+"']").tabs();
if ($(document).find("div[id='tabs"+json.Data.SearchResults.Results[i].Counter+"']").length > 0)
alert("it exists");
else
alert("it dont");
}
}
Suffice to say the alert box "it exists" appears successfully so it is finding the dynamically created html tab that the template generated however the tab itself is not being initialized by the statement:
$(document).find("div[id='tabs"+json.Data.SearchResults.Results[i].Counter+"']").tabs();
Does anybody know the reason why or what I'm missing here to get my .tabs() function to fire ...
I've examined the dynamic content and double checked the html code using firebug inspector and everything is according to how it should be the id's are correct, the #id's are there and so on, so my only conclusion is that the .tabs() function is not firing. Is this a limitation on the JQuery tabs itself? Can it not perform this type of "live" loading capability? Is there a callback function I should be using as part of loading the template itself?
Here is a picture of what is being returned after the call to the server without the tabs working:
发布评论
评论(1)
好吧,我解决了这个问题,我想我最好为那些遇到类似问题的人提供我的答案。
我应该将 for 循环放在与 tmpl 调用相同的回调函数内,例如:
我在这段代码之后有 for 循环,并且 tabs() 函数本质上根本没有引用新创建的选项卡。
Okay I fixed the problem, and thought I'd better give my answer for those of you who suffer a similar problem.
I should have placed my for loop inside of the same callback function as the tmpl call e.g:
I had the for loop after this block of code and the tabs() function essentially was not referencing the newly created tabs at all.