B4J Question [BANano]: [SOLVEd] How to CallSub inside #If JavaScriptSmart?

Mashiane

Expert
Licensed User
Longtime User
Hi there

I'd like to call a b4j function inside a javascript function, here is an example..

B4X:
#if JavascriptSmart
$(document).on('pagebeforeshow', '#headline', function(){
  ${BANano.CallSub(Me, "LoadSelectedMovie", Null)}
});
#End If

Sub LoadSelectedMovie
    'clear the listview content
    ml.clear
    'get list of movies
    movies = modMovies.moviesList
    Log(movies)
End Sub

This is inside a class module called headline.

Thanks.

PS: This currently works but need to do it the banano way:

B4X:
_banano_moviedb_headline.loadselectedmovie();
 

alwaysbusy

Expert
Licensed User
Longtime User
This can currently not be done (maybe in a class, but certainly not in a module).

It will be possible in the next version like this:

B4X:
Sub Process_Globals
   ...
   Private MethodLoad As Object
End Sub

'create the page
Public Sub Create(thisApp As JQMApp)  
   ...  
   MethodLoad = BANano.CallBack(Me, "LoadSelectedMovie", Null)       
End Sub

#if JavascriptSmart
$(document).on('pagebeforeshow', '#headline', function(){
  ${MethodLoad}  
});
#End If
'
Sub LoadSelectedMovie
...

However, a much better way is doing it the real 'BANano' way:

At the end of your create method:
B4X:
...
   Dim JQ As BANanoObject
   JQ.Initialize("$")
   
   Dim document As BANanoObject = BANano.Window.GetField("document")
   JQ.Selector(document).RunMethod("on",Array("pagebeforeshow", "#headline", BANano.CallBack(Me, "LoadSelectedMovie",Null)))
End Sub

Alwaysbusy
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
The last solution is perfect, thing is there are also other methods following the same methodology of handling pages before, during after they show. Ta!

B4X:
Sub PageBeforeShow(pgID As String, methodName As String, methodArgs As List, EventHandler As Object)
    pgID = pgID.tolowercase
    pgID = $"#${pgID}"$
    Dim document As BANanoObject = BANano.Window.GetField("document")
    JQ.Selector(document).RunMethod("on",Array("pagebeforeshow", pgID, BANano.CallBack(EventHandler, methodName, methodArgs)))
End Sub

#OneNeedsToExploreThis BANanoObject stuff.

Thanks a million!
 
Upvote 0
Top