JustGage 使用 Raphael,正如这里所讨论的那样,它不符合 AMD 标准(因此不适用于 Require.js)。
我以前没有使用过 Require.js,也没有做过很多 JS,所以我正在努力解决这个问题。有很多试验和错误;)
使用此处建议的方法,我将 Raphael 模块拆分为单独的文件并分别包含它们,并猜测要为 JustGage 做什么。
require.config({
paths: {
//other links removed
'eve': 'vendor/eve/eve',
'raphael-core': 'vendor/raphael/raphael.core',
'raphael-svg': 'vendor/raphael/raphael.svg',
'raphael-vml': 'vendor/raphael/raphael.vml',
'raphael': 'vendor/raphael/raphael.amd',
'justgage': 'vendor/justgage/justgage.1.0.1.min'
},
shim: {
'eve': {
exports: "eve"
},
'raphael': {
deps: ['eve'],
exports: "Raphael"
},
'justgage': {
deps: ['raphael'],
exports: "JustGage"
}
}
});
但是说明然后说“在上述配置之后,您可以像其他 require-js 模块一样开始使用 Raphael”,这不是很有帮助;)
我想我需要在 main.js 中做点什么?
在我的cshtml页面中,我有
require(["raphael", "justgage"], function(JustGage) {
$(function() {
var a = new JustGage({
id: "pvgauge",
value: @Model.GaugeValues.PV,
min: @Model.PVGauge.MinValue,
max: @Model.PVGauge.MaxValue,
title: "Personal Volume",
label: "PV",
levelColors: gaugeSettings.levelColors,
levelColorsGradient: gaugeSettings.levelColorsGradient,
showInnerShadow: gaugeSettings.showInnerShadow,
shadowSize: gaugeSettings.shadowSize,
labelFontColor: '#7ACE30',
titleFontColor: gaugeSettings.titleFontColor,
valueFontColor: gaugeSettings.valueFontColor
});
});
});
现在这至少找到了 JustGage,但现在给出了错误'Raphael' is undefined.
(我也尝试过直接在cshtml文件中包含一个脚本但得到错误'Mismatched anonymous define() module: function (eve) {'
)
我的理解是否正确,Require.js 意味着事情不在全局范围内?JustGage 是否希望 Raphael 能够进入全球范围?
让 JustGage 工作有什么帮助吗?或者对适用于 Require.js 的“speedo”型仪表的等效库的建议?