Mr Toni WP
Mr Toni WP

Reputation: 191

How to get a value from a Kinetic object?

I'm trying to get the value "type":"c" from a Kinetic object c4000 and append it to a <div> called objectvalue. I can get the name from the object c4000, using getName(), but how do I get the "type":"c"?

{
    "c4000": {"x": 675, "y": 269, "plan":1, "name":"c4000", "img":"coordinator.png",
    "added":"datetime", "type":"c", "interval":"0", "comment":"text", "active":true,
    "value":"4c"}
}

 var getvalue = kinImages[index].type();
 $( "#objectvalue" ).append(getvalue);

Upvotes: 0

Views: 64

Answers (2)

markE
markE

Reputation: 105035

You have created nested objects.

So you must first get the first object--kinImages[index],

and then get the c4000 object within that first object--kinImages[index].c4000.type.

alert(kinImages[0].c4000.type);

// OR

alert(kinImages[0]["c4000"].type);

// OR if c4000 is the only first level object (as in your example)

alert(kinImages[0][0].type);

Upvotes: 0

TommyBs
TommyBs

Reputation: 9648

have you tried removing the brackets after "type()" as it's a property, not a function

   {
"c4000": {"x": 675, "y": 269, "plan":1, "name":"c4000", "img":"coordinator.png",
"added":"datetime", "type":"c", "interval":"0", "comment":"text", "active":true,
"value":"4c"}
}

 var getvalue = kinImages[index].type;
 $( "#objectvalue" ).append(getvalue);

Upvotes: 1

Related Questions