search

Home  >  Q&A  >  body text

javascript - How to write tabs in a data-driven way?

I hope everyone can talk about examples of using js or jquery instead of vue and other frameworks

Sorry for not making it clear. What I mean is to use data to drive the update of UI, instead of updating the data and updating the UI at the same time, like the example below

    var tabSwitch = (function(){
        var lastIndex = 0;

        return function(){
            //    点击tab导航,触发tab切换事件
            $('.oa-tab').on("click", ".oa-tab-nav", function(e){
                var index = $(this).index();
                $(".oa-tab").trigger("tab.switch", index);
            });

            $(".oa-tab").on("tab.switch", function(e, index){
                //    更新tab导航
                $(".oa-tab-nav").eq(lastIndex).removeClass('active');
                $(".oa-tab-nav").eq(index).addClass('active');
                //    更新tab内容
                $(".oa-tab-item").eq(lastIndex).removeClass('active');
                $(".oa-tab-item").eq(index).addClass('active');
                lastIndex = index;
            });
            //    初始化触发
            $(".oa-tab").trigger("tab.switch", 0);
        };
    })();


    tabSwitch();
黄舟黄舟2733 days ago3076

reply all(2)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-07-05 10:40:32

    The poster mentioned that there is only one display area, and the loading data is only regenerated in that display area based on the above options? If this is the case, actually when you click on the option, you first clear the display area, then call the corresponding data and generate the corresponding appearance and then add it to the display area

    reply
    0
  • 巴扎黑

    巴扎黑2017-07-05 10:40:32

    Data driven? Do you mean to dynamically request data via ajax when clicking a tab?

    reply
    0
  • Cancelreply