Bootstrap 3 + backbonejs - 切换导航无法打开

问题描述 投票:2回答:2

我正在为我的项目(https://izify.com/)使用jquery,backbonejs,underscorejs和bootstrap 3。这是我的源代码https://github.com/datomnurdin/izify-template。单击按钮时,我无法打开toogle导航。

这是切换导航的屏幕截图。

我的offcanvas.js

$(document).ready(function() {
  $('[data-toggle=offcanvas]').click(function() {
    $('.row-offcanvas').toggleClass('active');
  });
});

与backbonejs集成时有什么问题吗?

我从这里拿到模板,http://getbootstrap.com/examples/offcanvas/

演示网站:http://staging.revivalx.com/izify-template/

jquery twitter-bootstrap backbone.js
2个回答
2
投票

怎么这个......更干净的方式

define(['jquery', 'underscore','backbone','text!templates/home/homeTemplate.html'], function($, _, Backbone, homeTemplate){

 var HomeView = Backbone.View.extend({
 el: $("#page"),

 events: {
    'click [data-toggle=offcanvas]' :'toggleClass'
 }, 

 render: function(){
    this.$el.html(homeTemplate);
 },

 toggleClass: function (e) {
this.$('.row-offcanvas').toggleClass('active');
 }

});

 return HomeView;

});

0
投票

我删除了offcanvas.js

$(document).ready(function() {
  $('[data-toggle=offcanvas]').click(function() {
    $('.row-offcanvas').toggleClass('active');
  });
});

并把这行代码

$('[data-toggle=offcanvas]').click(function() {
        $('.row-offcanvas').toggleClass('active');
      });

进入HomeView.js

define([
  'jquery',
  'underscore',
  'backbone',
  'text!templates/home/homeTemplate.html'
], function($, _, Backbone, homeTemplate){

  var HomeView = Backbone.View.extend({
    el: $("#page"),

    render: function(){
      this.$el.html(homeTemplate);

                  $('[data-toggle=offcanvas]').click(function() {
                    $('.row-offcanvas').toggleClass('active');
                  });
    }

  });

  return HomeView;

});

它工作正常。

© www.soinside.com 2019 - 2024. All rights reserved.