gpt4 book ai didi

javascript - UI Bootstrap 选项卡在重新加载后保存事件选项卡

转载 作者:行者123 更新时间:2023-11-29 15:15:51 25 4
gpt4 key购买 nike

我需要在页面重新加载后显示事件标签。我发现我需要将事件选项卡名称存储到 session 或本地存储中。但对我来说这不起作用。这是 html

<uib-tabset>
<uib-tab active="active" ng-init="isActive = isActiveTab('Info', $index)" index="0" data-toggle="tab" href="#sectionInfo"
heading="Info" classes="tabovi" select="setActiveTab('Info')"></uib-tab>
<uib-tab active="active" ng-init="isActive = isActiveTab('Info 2',$index)" index="1" data-toggle="tab" href="#sectionInfoTwo"
heading="Info 2" classes="tabovi" select="setActiveTab('Info')"></uib-tab>
</uib-tabset>

这是 Controller

// Save active tab to localStorage
$scope.setActiveTab = function (activeTab) {
sessionStorage.setItem("activeTab", activeTab);
};

// Get active tab from localStorage
$scope.getActiveTab = function () {
return sessionStorage.getItem("activeTab");
};

// Check if current tab is active
$scope.isActiveTab = function (tabName, index) {
var activeTab = $scope.getActiveTab();
return (activeTab === tabName || (activeTab === null && index === 0));
};

谢谢

最佳答案

您需要存储索引而不是它的名称。引用以下代码片段:

HTML:

<uib-tabset active="active">
<uib-tab index="0" data-toggle="tab" heading="Info" select="setActiveTab(0)" classes="tabovi"></uib-tab>
<uib-tab index="1" data-toggle="tab" heading="Software config" select="setActiveTab(1)"></uib-tab>
<uib-tab index="2" data-toggle="tab" heading="Hardware config" select="setActiveTab(2)"></uib-tab>
<uib-tab index="3" data-toggle="tab" heading="Config" select="setActiveTab(3)"></uib-tab>
</uib-tabset>

Javascript:

$scope.setActiveTab = function (activeTabIndex) {
sessionStorage.setItem("activeTab", activeTabIndex);
};

$scope.getActiveTab = function () {
return sessionStorage.getItem("activeTab");
};

// This will set last tab active automatically when page loaded
$scope.active = parseInt($scope.getActiveTab());

关于javascript - UI Bootstrap 选项卡在重新加载后保存事件选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49151219/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com