【发布时间】:2015-05-05 08:59:46
【问题描述】:
我在一个 Django 网站上工作,所以我有一个 base.html 包含我所有常用的东西,并将其扩展到我需要的页面
整个站点使用的常用脚本在我的base.html:
<script src="/static/js/libs/jquery/jquery.js"></script>
<script src="/static/js/libs/jquery/jquery-ui-1.10.1.custom.min.js"></script>
<script src="/static/js/libs/bs3/bootstrap.min.js"></script>
我的 dashboard.html 扩展了 base.html ,我将 require.js only 用于 dashboard.html,它在最底部包含以下内容:
<script data-main="/static/js/dashboard/main" src="/static/js/libs/require/require.js" type="application/javascript"></script>
我的main.js
requirejs.config({
paths: {
'jquery': '../libs/jquery/jquery.min',
// NOTE 1
//'bootstrap': '../libs/bs3/bootstrap.min',
// Backbone JS & Co
"underscore": '../libs/underscore/underscore-min',
"backbone": '../libs/backbone/backbone-min',
// Dashboard Chart
"salesView": 'views/Sales/DailySalesView',
},
});
// Load Dashboard elements
require(["jquery", "underscore", "backbone", "salesView"], function ($, _, Backbone, SalesView) {
// Show modal when dashboard page loads
$('#loading-modal').modal('toggle');
}, function (err) {
console.log(err)
});
注意 1:
当我在main.js 中启用bootstrap 时,模式加载正常,但顶部导航栏下拉菜单ul.nav > li.dropdown 停止工作。
所以我在main.js 中禁用了bootstrap,因为bootstrap.js 已经添加到我的base.html 中。顶部导航栏下拉菜单现在可以使用但我收到以下错误
TypeError: $(...).modal is not a function
问:由于bootstrap.js 已经添加到我的base.html 中,我假设它已经加载并且main.js 应该可以访问它。为什么不是这样?我该如何解决?
任何帮助/建议将不胜感激。
提前致谢
【问题讨论】:
标签: jquery django twitter-bootstrap backbone.js requirejs