Jquery (metis-menu) not working with iron:router in meteor

自古美人都是妖i 提交于 2020-01-06 03:28:27

问题


I'm trying to implement a sidebar (leveraging the sidebar from sb-admin-2When I use the side bar as part of main.html, the toggles work perfectly fine. However, when I implement the same via iron:router and set the sidebar to be persistent, the sidebar loses the toggle/hide functionality. basically, the child level elements are always expanded and I have no means to hide those child level elements. Is there a work around to this?

I've the side bar code here in pastie --> This works when in client/main.html

But when I try the same from within a template such as this and pass it to iron:router via the below code, the toggle functionality is lost

router.js:

Router.configure({
      layoutTemplate: 'sidebar'
});

I read in this similar question that this has something to do with rendered callback but I'm not sure how I can get it to work here.


回答1:


This is how I resolved it.

AppLayout:

<template name="Index">
    <div id="wrapper">
        <!-- Navigation -->
        {{> navigationBar}}
        {{> Sidebar}}
        <div id="page-wrapper">
            <div class="row breadcrumbPosition">
                {{> breadcrumb}}
            </div>
            <!-- /.row -->
            <div class="row">
                <div class="col-xs-9 blockablelockable">
                    {{> yield}}
                </div>
            </div>
          </div>
        <!-- /#page-wrapper -->
    </div>
    <!-- /#wrapper -->
</template>

Sidbar.html is a template with the original sidebar implementation.

SidebarHelper.js contains an functino in onRendered which initializes the metis menu like so:

Template.Sidebar.onRendered( function(){

    $('.metisMenu').metisMenu({
      toggle: true // disable the auto collapse. Default: true.
    });
});


来源:https://stackoverflow.com/questions/38419804/jquery-metis-menu-not-working-with-ironrouter-in-meteor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!