[英]Raphael: Chaining “.data” to a raphael.js element
I'm having trouble chaining " .data " to a raphael.js element. 我在将“ .data ”链接到raphael.js元素时遇到麻烦。
When I try to retrieve the data later, I get " undefined ". 当我稍后尝试检索数据时,出现“ undefined ”。
Here's my fiddle: http://jsfiddle.net/HkNgT/9/ 这是我的小提琴: http : //jsfiddle.net/HkNgT/9/
//Draw:
paper.circle(circleCenterX, circleCenterY, circleCenterRadius)
.attr({'fill':'blue', 'stroke':'red', 'stroke-width':2, 'opacity': 0.8})
.data({"circleCenterX":circleCenterX,
"circleCenterY":circleCenterY,
"boxYPosition":boxYPosition,
"boxXPosition":boxXPosition})
.id = name+"-circle";
//Output:
console.log("data is = ", paper.getById(name+"-circle").data("circleCenterX"));
With this code, the " .data(...) " part just doesn't work . 使用此代码,“ .data(...) ” 部分将 无法正常工作 。
When I try to retrieve it (with paper.getById), it displays " data is = undefined ". 当我尝试检索它(使用paper.getById)时,它显示“ data is = undefined ”。
Other ways that I have tried: 我尝试过的其他方式:
//Doesn't work
paper.circle....
.data("circleCenterX",circleCenterX)
.data("circleCenterY",circleCenterY)
.data("boxYPosition",boxYPosition)
.data("boxXPosition",boxXPosition);
And another: 还有一个:
//Doesn't work
var c = paper.circle....;
c.data("circleCenterX",circleCenterX);
c.data("circleCenterY",circleCenterY);
c.data("boxYPosition",boxYPosition);
c.data("boxXPosition",boxXPosition);
And another: 还有一个:
//DOES work, but gives me huge performance losses
paper.circle....;
paper.getById(name+"-circle").data("circleCenterX",circleCenterX);
paper.getById(name+"-circle").data("circleCenterY",circleCenterY);
paper.getById(name+"-circle").data("boxYPosition",boxYPosition);
paper.getById(name+"-circle").data("boxXPosition",boxXPosition);
Any help? 有什么帮助吗?
So, just trying to help, I've never used raphael before. 因此,我只是在尝试提供帮助之前从未使用过raphael。 I assume you're trying to retrieve the
circleCenterX
value? 我假设您正在尝试检索
circleCenterX
值?
Inspecting the data
function, it looks as though it's only used for setting the value. 检查
data
功能,看起来好像仅用于设置值。 (It only returns a value, if you're setting a value). (如果您要设置一个值,它只会返回一个值)。
function (b,c){
var d = bb[this.id] = bb[this.id] || {};
if(arguments.length==1){
if(a.is(b,"object")){
for(var e in b)b[g](e)&&this.data(e,b[e]);
return this
}
eve("raphael.data.get."+this.id,this,d[b],b);
return d[b]
}
d[b]=c,eve("raphael.data.set."+this.id,this,c,b);
return this
}
(Afaict, eve
is an Event framework, bundled with Raphael
. Anyone know where the data goes from here?) (Afaict,
eve
是一个与Raphael
捆绑在一起的Event框架。有人知道数据从哪里来吗?)
So this isn't going to help. 因此,这将无济于事。
Inspecting the circle object, I was able to see/pull out a cx
value, which I assume is the circleCenterX
value that you're looking for... 检查圆形对象,我能够看到/拉出一个
cx
值,我认为这是您要查找的circleCenterX
值...
var circ = paper.getById(name+"-circle");
console.log("baseVal is = ", circ[0].cx.baseVal.value);
console.log("animVal is = ", circ[0].cx.animVal.value);
Gives 给
baseVal is = 100
animVal is = 100
Is this what you're looking for? 这是您要找的东西吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.