我正在完成关于 raphaelJS 的 peepcode 教程,但遇到了以下错误:Uncaught TypeError: undefined is not a function when using the following callback function in JQuery.
self.plotArray = function (theArray, drawingCallback) {
$(theArray).each(function (i, release) {
var xOffset = 0
, timeOffset = release.date.getTime() - self.startTime
, timeRatio = timeOffset / self.timeSpan
, graphWidth = self.paper.width - self.dotRadius * 2;
xOffset = graphWidth * timeRatio + self.dotRadius;
drawingCallback(release, xOffset);
});
};
调用 drawingCallback 函数时出现此错误。我从 peepcode 查看了完整的解决方案,但它似乎与这段代码所做的非常相似。我是 Javascript 的新手对我没有帮助吗?任何解决此问题的想法将不胜感激。
下面给出的是调用 app.js 的 index.html:
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/raphael.js"></script>
<script type="text/javascript" src="js/app.js"></script>
我现在附上 app.js 的完整代码:
function Timeline(domID, width, height, releases) {
if (!(this instanceof arguments.callee)) {
return new arguments.callee(arguments);
}
var self = this;
self.init = function () {
self.paper = Raphael(domID, width, height);
self.dotRadius = 26;
self.parseDates();
self.draw();
};
self.parseDates = function () {
self.parsedReleases = [];
$(releases).each(function (i, release) {
var epochSeconds = Date.parse(release.date),
parsedDate = new Date(epochSeconds);
self.parsedReleases.push({date:parsedDate,
version:release.version});
});
self.startTime = self.parsedReleases[0].date.getTime();
var endTime = $(self.parsedReleases).last()[0].date.getTime();
self.timeSpan = endTime - self.startTime;
};
self.draw = function () {
self.plotArray(self.parsedReleases);
};
self.plotArray = function (theArray, drawingCallback) {
$(theArray).each(function (i, release) {
var xOffset = 0
, timeOffset = release.date.getTime() - self.startTime
, timeRatio = timeOffset / self.timeSpan
, graphWidth = self.paper.width - self.dotRadius * 2;
xOffset = graphWidth * timeRatio + self.dotRadius;
drawingCallback(release, xOffset);
});
};
self.drawDotAndLabel = function (release, xOffset) {
var dot, label;
dot = self.paper.circle(xOffset, self.dotRadius, self.dotRadius);
dot.attr({
'stroke-width':0,
'fill':'#7E2217',
'fill-opacity':1.0
});
label = self.paper.text(xOffset, self.dotRadius, release.version);
label.attr({
'fill':'#ffffff',
'fontSize':20,
'fontFamily':"'Garamond', 'Franklin Gothic Medium', 'Gill Sans MT Condensed', 'Arial Narrow', 'sans-serif'"
});
};
self.init();
}
var timeline;
jQuery(function () {
timeline = new Timeline('timeline', 940, 81, [
{date:"June 25, 2004", version:"0.5"},
{date:"December 13, 2005", version:"1.0"},
{date:"March 18, 2006", version:"1.1.0"},
{date:"January 28, 2007", version:"1.2.0"},
{date:"December 7, 2007", version:"2.0.0"},
{date:"May 31, 2008", version:"2.1.0"},
{date:"November 21, 2008", version:"2.2.2"},
{date:"March 15, 2009", version:"2.3.2"},
{date:"November 26, 2009", version:"2.3.5"},
{date:"July 26, 2010", version:"3 RC1"},
{date:"August 30, 2010", version:"3.0"}
]);
});