jqueryui选项卡(1.9.1)在加载时激活 [英] jqueryui tabs (1.9.1) activate on load
问题描述
我有这样的代码:
var enTabs = {
"Layout": 0,
"Edit": 1,
"Stuff": 2
}
$("#tabs").tabs({
activate: function (event, ui) {
switch (ui.newTab.index()) {
case enTabs.Layout:
// loads remote data, processes it, draws it to this tab;
break;
case enTabs.Edit:
// loads remote data, processes it, draws it to this tab;
break;
case enTabs.Stuff:
// loads remote data, processes it, draws it to this tab;
break;
}
}
}).tabs("option","disabled",[enTabs.Edit,enTabs.Stuff]);
console.log("active tab", $("#tabs").tabs("option","active")); // says "0"
按照jQuery按设计"声明( http://bugs.jqueryui.com/ticket/8735 ),第一次绘制选项卡时不会处理activate
事件;或者,当您设置.tabs("option","active",enTabs.Layout)
时,如果当前索引与您设置的选项/活动匹配,并且初始化为零,则激活不会触发.
As per the jQuery "by design" statement (http://bugs.jqueryui.com/ticket/8735), the activate
event isn't handled when the tab is first drawn; OR when you set .tabs("option","active",enTabs.Layout)
since activate won't fire if the current index matches the option/active that you set, and it's initialised to zero.
最好的方法是确保在第一次绘制选项卡时,对第一个(第0个)选项卡触发激活",从而意识到我不想绑定到创建",因为我不想将数据加载到选项卡上直到被实际单击?
What is the best way to ensure that when first drawing the tabs, that 'activate' is fired for the first (0th) tab, realising that I don't want to bind to 'create' since I don't want to load data on tabs until they are actually clicked ?
我没能力做
$("#tabs").tabs( "option", "active", -1 ).tabs( "option", "active", enTabs.Layout)
始终如一地工作.
推荐答案
您可以使用类似的
function loadTab(index) {
switch (index) {
case enTabs.Layout:
// loads remote data, processes it, draws it to this tab;
break;
case enTabs.Edit:
// loads remote data, processes it, draws it to this tab;
break;
case enTabs.Stuff:
// loads remote data, processes it, draws it to this tab;
break;
}
}
$(function () {
$("#tabs").tabs({
create: function (event, ui) { loadTab(ui.tab.index()) },
activate: function (event, ui) { loadTab(ui.newTab.index()) }
});
});
这里有一个类似的问题 JQuery UI选项卡1.10.0激活是创建后未调用
there is a similar question here JQuery UI tabs 1.10.0 activate is not called after creation
这篇关于jqueryui选项卡(1.9.1)在加载时激活的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!