Question

Is there any methods in KineticJS or in javascript that will allow you to dump object properties and their values.enter code here

Était-ce utile?

La solution

All properties that have been set on a Node are in the yourObject.attrs object.

Heres example code:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Prototype</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
    <script src="http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v4.7.2.min.js"></script>
<style>
body{padding:20px;}
#container{
  border:solid 1px #ccc;
  margin-top: 10px;
  width:350px;
  height:350px;
}
</style>        
<script>
$(function(){

    var stage = new Kinetic.Stage({
        container: 'container',
        width: 350,
        height: 350
    });
    var layer = new Kinetic.Layer();
    stage.add(layer);

    var circle1 = new Kinetic.Circle({
        x:100,
        y:100,
        radius: 30,
        fill: 'red',
        stroke: 'black',
        strokeWidth: 4,
        draggable: true
    });
    layer.add(circle1);
    layer.draw();

    enumerateAttributes(circle1);

    function enumerateAttributes(node){
        var text="";
        var attrs=circle1.getAttrs();
        for (key in attrs) {
            if (attrs.hasOwnProperty(key)) {
                text+=(key+"=="+attrs[key]+"\n");
            }
        }
        alert(text);
    }

}); // end $(function(){});

</script>       
</head>
<body>
    <div id="container"></div>
</body>
</html>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top