问题
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