我想在使用RequireJS的backbone.js应用程序中包含jQueryUI.index.html中包含的main.js文件如下:
require.config({
paths: {
jquery: 'libs/jquery/jquery-1.7.2.min',
jqueryui: 'libs/jquery/jquery-ui-1.8.18.custom.min',
underscore: 'libs/underscore/underscore-min',
backbone: 'libs/backbone/backbone-optamd3-min',
text: 'libs/require/text',
templates: 'templates'
}
});
require(['app'], function(App){
App.start();
});
Run Code Online (Sandbox Code Playgroud)
对于每个模型/视图/路由器文件,我只是在"define"块的开头包含'jquery'命名空间,如下所示:
define([
'jquery',
'underscore',
'backbone',
'views/categoryview',
'text!templates/category.html'
], function($, _, Backbone, CategoryView, categoryTemplate){
// Here comes my code
});
Run Code Online (Sandbox Code Playgroud)
但是jQueryUI无法在这些文件中使用.我的代码有问题吗?或者我是否还应在每个"定义"块中包含"jqueryui"?但是如果我在"define"块中包含"jqueryui",我应该如何在函数中命名它以避免名称与jquery冲突?
救命!
我是超级迷茫的家伙......我不知道我在做什么
昨天和今天我一直在关注RequireJS和AMD教程和示例,并且到了这一点,但是我认为我仍然对模块是什么有一个根本的误解.
我使用的是Node v0.10.12
<html>
...
<head>
<script data-main="" src="libraries/require.js"></script>
...
<script>
...
//I really need all these javascript files for every function defined on this page...
require(['simulatorConfiguration.js',
'modelConfiguration.js',
'libraries/jquery-1.10.2.min.js',
'libraries/jquery.lightbox_me.js',
'libraries/jquery-migrate-1.2.1.js',
'libraries/raphael-min.js'], function(start) {
$(function() {
loadPage(); //<--- CALL LOAD PAGE, but it can't find the function
//do some jquery stuff
});
});
//function that get's called on body onload!
define('loadPage', function loadPage()
{
hideAllDivs();
//more …Run Code Online (Sandbox Code Playgroud)