相关疑难解决方法(0)

如何使用RequireJS在我的模块化backbone.js应用程序中包含jQueryUI?

我想在使用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冲突?

jquery-ui requirejs backbone.js

13
推荐指数
1
解决办法
9298
查看次数

基本RequireJS帮助 - 如何调用/定义函数?使用onclick和jquery也是如此

救命!

我是超级迷茫的家伙......我不知道我在做什么

昨天和今天我一直在关注RequireJS和AMD教程和示例,并且到了这一点,但是我认为我仍然对模块什么有一个根本的误解.

  • 我有一堆函数从我的HTML元素中被称为"onClick"...
    1. 如何使用RequireJS 定义我的函数以便我可以调用它们?很困惑:/我也不明白
    2. 如何让我的onLoad函数被调用(在我的情况下是$(function(),但是如何在RequireJS中启动它?)

我使用的是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)

javascript jquery amd requirejs js-amd

13
推荐指数
1
解决办法
1万
查看次数

标签 统计

requirejs ×2

amd ×1

backbone.js ×1

javascript ×1

jquery ×1

jquery-ui ×1

js-amd ×1