Determining jQuery dependency for a module with Durandal in HotTowel SPA

I am going around trying to understand RequireJS and how to use it to load dependencies that DO NOT display as Undefined when I try to use them in modules.

I started with John Papa Puralsite SPA SPA with HTML5. What I never understood was due to the need to specify each library in the script tag that came into the kit when I thought that the whole point of AMD in requireJS is that you gave it the responsibility and its data-main attribute asynchronously upload what is required. What was doubly confusing in the solution presented in this course was that it did not match the entire core database documented in the RequireJS documentation.

Move for a few months, and now we have the "Hot Towel" template with Durandal, a sample of the "service" module, a setup that follows the RequireJS documentation and a fairly easy to understand starter. The only thing that sounds like an alarm clock is the idea that most libraries are in the regular “scripts” folder, and Durandal is in a completely separate “application” folder along with the application logic. If I learned one thing from the SPA multiple-choice procedure and play with requireJS, this movement of material from one folder occurs very quickly, very quickly.

Anyway, the new template works fine. The module dependencies work fine, Views and ViewModels are required, and the logbook module works with the module dependency on the Durandal module (that is, in the application folder), which works fine. It should just add another simple module that uses jQuery and mockJson based on the code in the Hot Towel template, right? Err, no, not really.

Here is a very simple declaration to start my module "dataservice.js" inside the folder "app / services"

define(['jquery'],
function ($) {
    var init - function....

, , 'undefined' $, . ( , : " jquery xxxx, " ) :

  • , , jQuery , mockJSON, , BundleConfig.cs. , jQuery , . "undefined" , , - :

    require.config({
        paths: {
            'text': 'durandal/amd/text',
            jquery: '../Scripts/jquery-1.9.1'
        }
    });
    

    ( "text". jquery). , "undefined", , , script - Hot Towell. jQuery , ?

  • mockJSON "vendor", $.mockJSON. , . script, , jquery require.config({paths: ', undefined, , " " , . , ?

  • , , requireJS - , jQuery mockjson , ( ) , requireJS , , , , . / ? Durandal, jQuery , , jquery, , , , Durandal, - . , requireJS, , , "../" , . - , " , Durandal, , Durandal " ?

  • , requireJS " " define, , , , . , "" . , "Durandal/transition/entry.js", , - "", "Durandal//". ?

  • , (hoorah) ( ) define , factory, , - var system = require ('../system') - , . , , .

PS. , 1 5. , , 1, 1 4. HTML- , , , , , , 1 5, 2 1 2 4!)

+5
4

, !

durandal google: https://groups.google.com/forum/#!searchin/durandaljs/papa/durandaljs/Ku1gwuvqPQQ/gupgNqGIK1MJ

, , Hot Towel, script, require/AMD . jquery ($) (ko).

, , require/AMD, , , - AMD. ( , ).

, , , durandal, .

+2

, ! .

jQuery .., main.js # 6, , .

var root = this; // the global namespace, window

// The following are already loaded via bundles 
// which put them in the root object. Add them as services.
define('jquery', [], function () { return root.jQuery; });
define('ko', [], function () { return root.ko; });
define('breeze', [], function () { return root.breeze; });
define('Q', [], function () { return root.Q; });
define('moment', [], function () { return root.moment; });
define('sammy', [], function () { return root.Sammy; });
define('toastr', [], function () { return root.toastr; });

?:)

+1

. - - (, Durandal) jQuery - , , ( , - Durandal, . jQuery ()). , " " /. jQuery, .

** jQuery, , , - main.js, script requireJS:

require.config({
paths: {
    'text': 'durandal/amd/text',
    'mockjson': '../Scripts/jquery.mockjson.js'
},
shim: {
    'mockjson': {
        deps: ['jquery'],
        exports: ['mockJSON']
    }
}

});

, mockJSON ( "vendor", ), , , jQuery, , (, , , ).

, , , , Code Camper John Papa - , , ( . , - , , Durandal, " " ). , , , (, ", , , requireJS , :" . "," , , , "more.info.txt", / ? ";" , (, , , ? " script , ( , )?" " NetEye IsBusy script h " KoLite "?" .. ..

, , -, , , ( , - , , " " jquery , ). , , , " Pluralsight, . , , , , , , . !

, - requireJS; -)

0

What is late for. Durandal improved the documentation on this issue. The Dependency Configuration section on the page below explains the difference between registering modules with define (alias, globalVariable) and using paths and a layout strategy.

Both work, but if you use path and strip, all dependencies should be registered in the same way. This is especially true for plugins using "jQuery.fn.extend ...".

http://durandaljs.com/documentation/Conversion-Guide/

0
source

All Articles