gpt4 book ai didi

javascript - RequireJS 和 KendoUI - Shim jQuery 依赖

转载 作者:行者123 更新时间:2023-11-29 22:01:25 24 4
gpt4 key购买 nike

我正在尝试学习 KendoUI 和 RequireJS。
我创建了在加载时显示窗口的简单应用程序。

我的 require.config 看起来像这样:

require.config({
paths: {
jQuery: [
'http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.min',
'libs/jquery-2.1.0'
],
underscore: [
'http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min',
'libs/underscore'
],
handlebars: [
'http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/2.0.0-alpha.2/handlebars.min',
'libs/handlebars'
],
k: 'libs/kendo',
text: 'libs/require/text',
async: 'libs/require/async',
templates: 'templates'

},
shim: {
'jQuery': {
exports: '$'
},
'underscore': {
exports: '_'
},
'handlebars': {
exports: 'Handlebars'
},
"k": {
deps: ["jQuery"]
}
}
});

和我的主要:

require(['jQuery', 'handlebars', 'helpers/handlebarsHelper', 'k/kendo.notification', 'k/kendo.window'], function ($, Handlebars, hh) {

hh.init();

var context = {
people: [{
firstName: "Yehuda",
lastName: "Katz"
}, {
firstName: "Carl",
lastName: "Lerche"
}, {
firstName: "Alan",
lastName: "Johnson"
}]
};

var x = hh.getTemplate('test');
$('#container2').html(x(context));
var x = hh.getTemplate('test');
$('#container3').html(x(context));

var popupNotification = $("#popupNotification").kendoNotification({
position: {
top: 20,
right: 20
}
}).data("kendoNotification");

window.setInterval(function () {
var d = new Date();
popupNotification.show(kendo.toString(d, 'HH:MM:ss.') + kendo.toString(d.getMilliseconds(), "000"), "error");
}, 7000);

$("#window").kendoWindow({
width: "500px",
modal: true,
resizable: false,
actions: ["Close"],
title: "About Josef Hoffmann",
visible: false
}).data("kendoWindow").center().open();

});

我的应用程序可以运行,但有时会出现错误
Uncaught ReferenceError: jQuery is not defined

requirejs 有指定 shim 的选项,但它不适用于 KendoUI,可能是我做错了什么。

所以我的问题是:
我应该如何配置 requireJS 以使其与 KendoUI 一起工作?

最佳答案

我得到了这个工作,我不得不改变 shim 配置:

shim: {
'jQuery': {
exports: '$'
},
'underscore': {
exports: '_'
},
'handlebars': {
exports: 'Handlebars'
},
"kendo/kendo.core": {
deps: ["jQuery"]
}
}

kendo.core 依赖于 jQuery,所以我问题中的这部分代码导致了错误。

关于javascript - RequireJS 和 KendoUI - Shim jQuery 依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23545011/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com