我正在开发一个使用Globalize.js的ASP MVC应用程序.在_Layout.cshtml中,我添加了此代码
<script>
(function () {
$(function () {
$.when(
$.getJSON("@Url.Content("~/Scripts/cldr/supplemental/likelySubtags.json")"),
$.getJSON("@Url.Content("~/Scripts/cldr/main/fr/numbers.json")"),
$.getJSON("@Url.Content("~/Scripts/cldr/supplemental/numberingSystems.json")"),
$.getJSON("@Url.Content("~/Scripts/cldr/main/fr/ca-gregorian.json")"),
$.getJSON("@Url.Content("~/Scripts/cldr/main/fr/timeZoneNames.json")"),
$.getJSON("@Url.Content("~/Scripts/cldr/supplemental/timeData.json")"),
$.getJSON("@Url.Content("~/Scripts/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 () {
Globalize.locale("fr");
});
});
})();
</script>
它正在发挥作用.但是当我尝试在$(document).ready或$(window).load中的其他页面中使用它时我有错误JavaScript:E_DEFAULT_LOCALE_NOT_DEFINED:尚未定义默认语言环境.
似乎全球化尚未加载.
最佳答案 当您尝试使用Globalize静态函数(例如,Globalize.formatMessage)而未事先设置区域设置默认值(例如,Globalize.locale(“fr”))时,会发生E_DEFAULT_LOCALE_NOT_DEFINED错误.
您能否提供有关触发上述错误的代码的更多详细信息?