Bootstrap 3 + backbonejs – 切换导航无法打开
我正在为我的项目使用jquery,backbonejs,underscorejs和bootstrap 3( https://izify.com/ )。 这是我的源代码https://github.com/datomnurdin/izify-template 。 单击按钮时,我无法打开toogle导航。
这是toogle nav的屏幕截图。
我的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/
怎么这个……更清洁的方式
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; });
我删除了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; });
它工作正常。