hi
i am working a very big project with b4j and jserver.
i am creating dynamically html elements and update the inner HTML of the relevant div in my webpage.
i am using for that specific page a WebSocket now my question is this. i need to trigger several events for some dynamically created elements like _click, _changed ...
i cannot add the click event for the whole div and use the target element because it will break other features in my app so what i do now is adding js code dynamically to those elements like a click listener with ws.Eval() function and a callback to a b4j event.
is this a good approach? is there a better way to do that?
example:
b4j event:
everything works fine, i am just wondering if this is the right approach or maybe i should do it in a different way?
thanx
i am working a very big project with b4j and jserver.
i am creating dynamically html elements and update the inner HTML of the relevant div in my webpage.
i am using for that specific page a WebSocket now my question is this. i need to trigger several events for some dynamically created elements like _click, _changed ...
i cannot add the click event for the whole div and use the target element because it will break other features in my app so what i do now is adding js code dynamically to those elements like a click listener with ws.Eval() function and a callback to a b4j event.
is this a good approach? is there a better way to do that?
example:
B4X:
Dim js As String = $"
$(".menuitem").click(function() {
let itemid = jQuery(this).attr("itemid");
let itemtype = jQuery(this).attr("itemtype");
b4j_raiseEvent("remove_Item",{id:itemid,type:itemtype});
});
"$
ws.Eval(js,Null)
b4j event:
B4X:
Sub remove_Item(Params As Map)
Log(Params.Get("id"))
Log(Params.Get("type"))
End Sub
everything works fine, i am just wondering if this is the right approach or maybe i should do it in a different way?
thanx