07.03.2023, 10:34
Hi,
I´m doing a widget with dynamic object address and I need to remove listeners when I close widget or when I open it again with another address.
How can i do that?
Thanks!
I´m doing a widget with dynamic object address and I need to remove listeners when I close widget or when I open it again with another address.
Code:
// Declare vars
var ObjEscucha = "0/0/0";
var MainObjectSplitted = [];
var DirOriginales = ["8/1/102","8/1/103"];
var DirWrNuevas = ["1/1/1","1/1/2"];
var DirWrSustituidas = []
var DirEstadosReales = [["0/2/0","0/2/1"],["0/3/1","0/3/2"]]
var DirEstSustituidas = [["Es la 0/2/0","Es la 0/2/1"],["H","ADIOS"]]
function actualizarEstados(a,b) {
return function (obj) {
console.log(DirEstSustituidas[a][b])
};
}
function removelistener(src) {
var el = $(src) // source element reference
, addr = el.data('status-object') // group address of status object
, id = Scada.encodeGroupAddress(addr) // address to id
, obj = objectStore.objects[ id ]; // get object's store reference
if (obj) {
// find listener that is attached to the source element
console.log(addr)
$.each(obj.listeners, function(index, listener) {
// remove the listener
if (listener.bind.el && el.is(listener.bind.el)) {
obj.listeners.splice(index, 1);
}
});
}
}
// Detect adresses linked to widget button and create arrays
$(".screen_widget").on("click", function(e) {
ObjEscucha = $(this).data("object");
for (var i = 0; i < DirOriginales.length; i++) {
if (ObjEscucha == DirOriginales[i]){
DirWrSustituidas = DirWrNuevas[i]
//I NEED TO REMOVE THIS LISTENER WHEN I OPEN AGAIN THE WIDGET
for (var j = 0; j < DirEstadosReales[i].length; j++) {
grp.listen(DirEstadosReales[i][j], actualizarEstados(i,j));
}
}
}
});
How can i do that?
Thanks!