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

Discussion in 'B4J Questions' started by Mashiane, Jan 24, 2019.

  1. Mashiane

    Mashiane Expert Licensed User

    Hi there

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

    Code:
    #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:

    Code:
    _banano_moviedb_headline.loadselectedmovie();
     
  2. alwaysbusy

    alwaysbusy Expert Licensed 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:

    Code:
    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:
    Code:
    ...
       
    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
     
    Mashiane likes this.
  3. Mashiane

    Mashiane Expert Licensed 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!

    Code:
    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!
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice