Jquery Globalize setup using plain javascript - uncaught error

混江龙づ霸主 提交于 2019-12-04 04:05:20

问题


I am trying to setup jquery globalize using the js/json setup suggested (for date module), using a javascript example suggested here.
In this code I am trying to set it up and the use it to format the jquery-ui datepicker:

(function () {

$(function () {
    $.when(
      $.getJSON("/Scripts/cldr/cldr-json/cldr-core-master/supplemental/likelySubtags.json"),
      $.getJSON("/Scripts/cldr/cldr-json/cldr-numbers-modern-master/main/en/numbers.json"),
      $.getJSON("/Scripts/cldr/cldr-json/cldr-core-master/supplemental/numberingSystems.json"),
      $.getJSON("/Scripts/cldr/cldr-json/cldr-dates-modern-master/main/en/ca-gregorian.json"),
      $.getJSON("/Scripts/cldr/cldr-json/cldr-dates-full-master/main/en/timeZoneNames.json"),
      $.getJSON("/Scripts/cldr/cldr-json/cldr-core-master/supplemental/timeData.json"),
      $.getJSON("/Scripts/cldr/cldr-json/cldr-core-master/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 () {

        var culture = "en";
        Globalize(culture);
        $("input.datepicker").datepicker({
            prevText: '<i class="fa fa-chevron-left"></i>',
            nextText: '<i class="fa fa-chevron-right"></i>',
            dateFormat: Globalize.dateFormatter({ date: "short" })
        });
    });
});})();  

And the error I get is

E_DEFAULT_LOCALE_NOT_DEFINED: Default locale has not been defined. in globalize.js @ line 105

What am I doing wrong?


回答1:


I used same code and had same error. Instead of:

    var culture = "en";
    Globalize(culture);
    $("input.datepicker").datepicker({
        prevText: '<i class="fa fa-chevron-left"></i>',
        nextText: '<i class="fa fa-chevron-right"></i>',
        dateFormat: Globalize.dateFormatter({ date: "short" })
    });

I just had: Globalize.locale("en"); and that fixed it.

  • Make sure your function is called
  • Make sure all your json objects are fetched


来源:https://stackoverflow.com/questions/32753888/jquery-globalize-setup-using-plain-javascript-uncaught-error

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