requirejs计时问题 - 一些bootstrap js不起作用

时间:2016-01-07 17:22:38

标签: javascript asp.net twitter-bootstrap requirejs

自从开始使用requireJs以来,我遇到了一个奇怪的问题。这个问题似乎只发生在一些侧栏菜单项上,可以展开以查看子菜单项。在

之前的最后调用RequireJS模块
  

标签,页面上的其他JS本身工作正常,只是没有这个侧边栏菜单。非常感谢您的帮助,因为我已经和我斗争了好几天了!

布局视图:

<body>
    ...Ouput ommited for brevity
    <ul class="nav nav-list">
        <li>
            <a href="#" class="dropdown-toggle">
                <i class="menu-icon fa fa-desktop"></i>
                <span class="menu-text">  Devices  </span>
                <b class="arrow fa fa-angle-down"></b>
            </a>

            <b class="arrow"></b>

            <ul class="submenu">
                <li>
                    <a href="#" class="dropdown-toggle">
                        <i class="menu-icon fa fa-caret-right"></i>
                        CA Spectrum
                        <b class="arrow fa fa-angle-down"></b>
                    </a>

                    <b class="arrow"></b>
                </li>
            </ul>
        </li>
    </ul>
    ...Output ommited for brevity

    @RenderSection("scripts", required: false)

</body>
  

“dropdown-toggle”类是bootstrap.js用来做的事情   下拉行为。

包含在“布局”视图底部呈现的脚本部分的子视图:

@section scripts {
    <script data-main="/Scripts/dist/app" src="~/Scripts/dist/require.js"></script>
    <script>
            var ajaxUrl = '@Url.Content(url)';
        require(['app'], function () {
            require(['casnodes-downtime']);
        });
    </script>
}

app.js

requirejs.config({
    baseUrl: "/Scripts/dist/",
    paths: {
        "requireLib": "./require",
        "app": "./app",
        "main": "./main",
        "jquery": "./jquery-2.1.4",
        "jqbsace": "./jqbsace",
        "datatables": "./jquery.dataTables",
        "moment": "./moment",
        "momentTZ": "./moment-timezone",
        "momentDF": "./moment-duration-format",
        "datarangepicker": "./daterangepicker/daterangepicker",
        "highstock": "./highstock",
        "highmaps": "./highmaps",
        "bootstrap": "./bootstrap",
        "aceconcat": "./aceconcat",
        "jstz": "./jstz-1.0.4.min",
        "shared": "./controllers/shared1",
        "usa": "./us-all",
        // Controller modules
        "casnodes-chronicnodes": "./controllers/casnodes/chronicnodes",
        "casnodes-downtime": "./controllers/casnodes/downtime",
        "casnodes-downnodes": "./controllers/casnodes/downnodes",
        "casnodes-nodedowntime": "./controllers/casnodes/nodedowntime"
    },
    shim: {
        "highstock": ["jquery"],
        "jstz": {
            exports: "jstz"
        },
        "bootstrap": ["jquery"],
        "aceconcat": ["bootstrap"],
        "momentDF": ["moment"],
        "highmaps": ['jquery'],
        "usa": ['jquery', 'highmaps']
    }
});

requirejs(["main"]);

main.js

define([], function () {

});

casnodes-downtime模块

define(["jquery", "moment", "jstz", "momentDF", "momentTZ", "datatables", "highstock", "datarangepicker", "aceconcat"], function ($, moment) {
    $(document).ready(function () {
     ...Output ommited for brevity
    });
});

1 个答案:

答案 0 :(得分:-2)

你应该使用

$(document).on('keydown', function(e)
{
   var shifted = e.shiftKey;
   var downTime = parseInt( $(this).attr( "data-startTimer") );
   console.log( shifted );
   if ( shifted && isNaN( downTime ) )
   {
     console.log( downTime );
     $(this).attr( "data-startTimer", new Date().getTime() );
   }
});

$(document).on('keyup', function(e)
{
  var downTime = parseInt( $(this).attr( "data-startTimer") );
  if ( !isNaN( downTime ) )
  {
     console.log( ( new Date().getTime() - downTime ) );
     if (  ( new Date().getTime() - downTime ) >= 5000 )
     {
        console.log( "yesss" );
        alert( "you held shift key for 5 seconds or longer" );
     }
  }
  $(this).attr( "data-startTimer", "null" );
});

      require(['app','casnodes-downtime'], function () {

      });

不要混淆它们。