I have an object with some attributes and would like to store the value of one (the attribute is "state" and has value "closed") in a variable to compare its value by an "if" statement. What I'm looking for is doing something depending on the value of the "state" attribute.
I've tried something like that but it does not work:
var tipo = objeto.getAttribute('estado', 'cerrado');
if (tipo == 'cerrado') {
//ejecución
} else {
//ejecución
}
The object is the following:
// Pulsador Cerrado
var pulsador_cerrado = joint.shapes.basic.Generic.define('electrics.pulsador_cerrado', {
size: {width: 80, height: 40},
position: {x: 50},
attrs: {
'.': {magnet: false},
'.body': {width: 50, height: 25},
'.input': {ref: '.body', 'ref-x': -4, 'ref-y': 0.5, magnet: true, port: 'in'},
'.output': {ref: '.body', 'ref-x': 84, 'ref-y': 0.5, magnet: true, port: 'out'},
circle: {r: 5, stroke: 'black', fill: 'transparent', 'stroke-width': 1},
image: {'xlink:href': 'pulsador.nc.jpg'},
**estado: 'cerrado'**
},
});
Do you know how to store the value of an attribute of an object and how to compare the value of that attribute with another value?
Pd: I'm using joint library and jquery.
Greetings and thanks