繁体   English   中英

Raphael:将“ .data”链接到raphael.js元素

[英]Raphael: Chaining “.data” to a raphael.js element

我在将.data ”链接到raphael.js元素时遇到麻烦。

当我稍后尝试检索数据时,出现“ undefined ”。

这是我的小提琴: 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"));

使用此代码,“ .data(...)部分将 无法正常工作

当我尝试检索它(使用paper.getById)时,它显示“ data is = undefined ”。

我尝试过的其他方式:

    //Doesn't work
    paper.circle....
    .data("circleCenterX",circleCenterX)
    .data("circleCenterY",circleCenterY)
    .data("boxYPosition",boxYPosition)
    .data("boxXPosition",boxXPosition);

还有一个:

    //Doesn't work
    var c = paper.circle....;
    c.data("circleCenterX",circleCenterX);
    c.data("circleCenterY",circleCenterY);
    c.data("boxYPosition",boxYPosition);
    c.data("boxXPosition",boxXPosition);

还有一个:

    //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);

有什么帮助吗?

因此,我只是在尝试提供帮助之前从未使用过raphael。 我假设您正在尝试检索circleCenterX值?

检查data功能,看起来好像仅用于设置值。 (如果您要设置一个值,它只会返回一个值)。

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是一个与Raphael捆绑在一起的Event框架。有人知道数据从哪里来吗?)

因此,这将无济于事。

检查圆形对象,我能够看到/拉出一个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);

baseVal is =  100
animVal is =  100

这是您要找的东西吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM