【发布时间】:2011-11-13 19:22:25
【问题描述】:
我从 Mootools 框架开始。由于我希望代码可重用,因此我尝试使用类来实现。
在下面显示的代码中,目的是使用 Raphael 框架为 SVG 绘制地图。代码工作正常,但我遇到了 Options 对象内的属性问题。
var Map = new Class({
Implements : [ Options ],
pathsArr: {},
Options: {
canvas: {
container: 'map',
cheight: 500,
cwidth: 900,
},
attributes: {
fill: '#006699',
stroke: '#3899E6',
'stroke-width': 1,
'stroke-linejoin': 'round'
}
},
initialize: function (pathsArr, options){
this.setOptions(Options);
this.pathsArr = paths;
console.log(this.pathsArr);
},
setCanvas: function(){
console.log(this.Options.canvas);
R = Raphael(this.Options.canvas.container, this.Options.canvas.cwidth, this.Options.canvas.cheight);
return R;
},
drawPaths: function(){
console.log(this.Options.attributes);
for (var country in this.pathsArr){
var shape = R.path(this.pathsArr[country].path);
var attri = this.Options.attributes;
console.log(attri);
}
}
});
好的,您可以看到我正在使用console.log 来了解这里的情况。当我检查该行中的属性时
console.log(this.Options.attributes);
我在 Google Chrome 控制台中得到了这个
当我认为我需要类似于检查 pathsArr 时发生的事情时,它位于 Options 对象之外。
在我需要 attributes 属性的地方没有任何反应。就像这两行一样。
var attri = this.Options.attributes;
shape.attr(attri);
我不明白为什么如果我这样做,它会得到正确的结果。
console.log(this.Options.attributes.fill);
好吧,就是这样,我被困住了,我希望有人能向我解释为什么会这样。谢谢!!
【问题讨论】:
标签: javascript mootools raphael options