globalize.js: dynamic loading

你离开我真会死。 提交于 2019-12-11 23:49:29

问题


I am trying to the example for plain JS of the gloablize (https://github.com/jquery/globalize) running in an advanced way based on https://github.com/jquery/globalize/blob/master/doc/cldr.md.

Therefore I created a loader script to load all dependencies:

var url = new URL(window.location.href);
//STATIC_URL: global variable from base.html
$.when( 
        $.getScript( url.origin + STATIC_URL + "js/globalize2/cldrjs/cldr.js" ),
        $.getScript( url.origin + STATIC_URL + "js/globalize2/cldrjs/cldr/event.js" ),
        $.getScript( url.origin + STATIC_URL + "js/globalize2/cldrjs/cldr/supplemental.js" ),
        $.getScript( url.origin + STATIC_URL + "js/globalize2/globalize.js" ),
        $.getScript( url.origin + STATIC_URL + "js/globalize2/globalize/date.js" ),
        $.getScript( url.origin + STATIC_URL + "js/globalize2/globalize/number.js" ),
        $.getScript( url.origin + STATIC_URL + "js/globalize2/globalize/plural.js" ),

        $.Deferred(function( deferred ){
            $( deferred.resolve );
        })
).done(function(){
    $.when(
      $.get( url.origin + STATIC_URL + "js/globalize2/cldr/main/de/ca-gregorian.json" ),
      $.get( url.origin + STATIC_URL + "js/globalize2/cldr/supplemental/likelySubtags.json" ),
      $.get( url.origin + STATIC_URL + "js/globalize2/cldr/supplemental/timeData.json" ),
      $.get( url.origin + STATIC_URL + "js/globalize2/cldr/supplemental/weekData.json" )
    ).then(function() {

      // Normalize $.get results, we only need the JSON, not the request statuses.
      return [].slice.apply( arguments, [ 0 ] ).map(function( result ) {
          return result[ 0 ];
      });

    }).then( Globalize.load ).then(function() {

      // Your code goes here.

    }); 
});

All files are loaded correctly as far as i can see in Firebug. But when it comes to the Globalize.load step, the reference is marked as not defined.

I don't have a clue whats wrong at the moment. Any help welcome.

来源:https://stackoverflow.com/questions/26946511/globalize-js-dynamic-loading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!