Using Javascript in AppBuilder


John Clarke

I have a number of questions regarding using Javascript in App Builder. I have a number of JS files that contain Javascript that has been coded using an OO Approach and other external files When I build my app where would be the best place to put these files?

2. Do I add the External Files I need (JavaScript, CSS, Etc) via the App-File Manager?

3. Will the files I add via the App-File Manager automatically be included in the "Compiled" directory for the App when I build it?

4. In my code (taken from a HTML File) I create an instance of a class by using code like

I know that I can add this code to a button. However: How can I create it as a variable for the view that I am on for my app (if I can create variables at a view level)?

How can I create it as a global variable for the app?

Thanks in advance.


DecSoft

Hello John,

Yes; you must use the file's manager in order to include Javascript and Styles (CSS files) in your apps, because, App Builder not only copy these files into the app's "_Compiled" folder, but also link it into the app's "index.html" file, so their stuff are available to use in the app. Note that the file's manager rows establish the order for Javascript and Style files, that is, the order to follow later when link that files in the "index.html".

About where to place the variables, in fact you can use app's variables or not, depend on what you wanted. For example, is completely possible to write some Javascript like the below one:

In the above case we are create an variable in the "window" scope, which is not merelly an app's variable, but, since we always can use Javascript, we can reach that variable without problem when needed.

If you want to create an variable in the app's scope, you can also do it using a code similar than the below one:

The above means basically that you can reach the "MyTestClassInstance" variable using AB actions too. We can go ahead and place an variable in some specific app's view: if you need that, you can do it too, since all app's views have an object variable:

Please, ask here if you have any further questions or if I miss something.



John Clarke

Hi David,

Thanks for your reply. I have a few more questions - and I apologise if they seem trivial\silly.

Views

1. Are all views automatically created when the app starts running ?

2. Can views be dynamically created (e.g. when I click a button a view is dynamically created) or do you just show the view (e.g. using ReplaceView "NewView2") ?

Javascript

My Javascript file has the following code in it :

In your reply you said that I can use any of the following :

and that these would allow me to use AB Actions too.

I am just wondering where I would place these variable creation statements?

1. Would I place them in the "Ready" event on of the View (Master or normal view) ?

2. Would I place them in a Button that shows the view ? e.g.

3. Is there any way to refer to the current view without specifying its whole path (e.g. with something like this.View1) ?

Thanks in advance


DecSoft

Hello John,

1. Are all views automatically created when the app starts running ?

Not exactly. The HTML part of the views are loaded when needed, so, if you did not load an view, their HTML part is not loaded at all. Some stuff of the views are available from the scratch, for example, some variables, but, certainly other stuff cannot be available into the view is shown.

2. Can views be dynamically created (e.g. when I click a button a view is dynamically created) or do you just show the view (e.g. using ReplaceView "NewView2") ?

You can't create views dinamically. You must create it at designtime and then use actions like ShowView, ReplaceView and ShowDialog in order to show the appropriate view.

... and that these would allow me to use AB Actions too.

Only if you set an app's variable can use later AB actions to deal with that variable. Only if you place the variable in the app's root scope like in:

But the point is what you need, John. Commonly we no need to use thirdparty Javascript, or, just a few Javascript code in certain situations. If you plain to use thirdparty Javascript, then you must know about how to use that Javascript, and, in fact the AB context is more or less important, since finally we are talking about HTML apps, then, you must use the Javascript in a similar way that if you use it in any other HTML app.

I am just wonderiang where I would place these variable creation statements? 1. Would I place them in the "Ready" event on of the View (Master or normal view) ? 2. Would I place them in a Button that shows the view ? e.g.

That's is what I am saying. You must create your Javascript... when and where you need it... If you need it from the scratch, then you can use the app's Ready event. If you need it when an app's view HTML is ready, you must use the view's Show event. If you only need in certain location, may you can create it in an control's Click event, for example, etc.

3. Is there any way to refer to the current view without specifying its whole path (e.g. with something like this.View1) ?

Maybe in some places, yes, but, since some other places can require the whole path, probably is good to always refer to the whole part. IMHO.


Todo el mundo puede leer el foro de soporte de DecSoft para aprender del mismo, sin embargo, sólo los clientes de DecSoft pueden abrir nuevos hilos. Compre una o más licencias de productos de DecSoft y obtendrá este y otros beneficios.

Este sitio utiliza "cookies" útiles para almacenar sus preferencias.

Bien. Ocultar esta nota. Obtener más información.