Communicating NeoScript and Javascript - Forum

Forum Navigation
You need to log in to create posts and topics.

Communicating NeoScript and Javascript

I have the following code:
CreateEmptyArray [poi]
CreateEmptyArray [poi.latitude]
CreateEmptyArray [poi.length]
CreateEmptyArray [poi.url]
beginjs
// operations with a Json
// and at a given moment I need to pass variables from js to neoscript
$App.poi.latitude(0)=latitude;
$App.poi.length(0)=length;
$App.poi.url(0)=poiUrl;
endjs
It works with normal variables, but what is the format when the variable is an array?
thank you!

@emmanuel-fernandez this is the correct syntax in JavaScript:

CreateEmptyObject [poi]
beginjs
latitude = 20;
longitude= 10;
poiUrl = "https://google.es";
$App.poi.latitude=latitude;
$App.poi.length=length;
$App.poi.url=poiUrl;
endjs
jsAlert [poi.url]

 

Or, if you want poi to be an Array of objects and store a collection of latitudes, etc.:

CreateEmptyArray [poi]
CreateEmptyObject [poi(0)]
BeginJS
  latitude = 20;
  longitude= 10;
  poiUrl = "https://google.es";
  $App.poi[0].latitude=latitude;
  $App.poi[0].length=length;
  $App.poi[0].url=poiUrl;
EndJS
jsAlert [poi(0).url]

 

emo has reacted to this post.
emo

Ok, thanks @luishp, the second example is closer to what I want, even so, the variables are increasing in the javascript code, so I need them to be created in new objects.
This only works for object(0)

CreateEmptyArray [poi]
CreateEmptyObject [poi(0)]
BeginJS
//read a file with a json in each line and gets latitud, longitud y poiUrl.
//los asigana a poi(0)
   $App.poi[0].latitud=latitud;
   $App.poi[0].longitud=longitud;
   $App.poi[0].url=poiUrl;
//fin de bucle

EndJS
jsAlert [poi(0).url]
. lo representa en el mapa
neoMapAddMarker "Container2" "" "blue" [poi(0).latitud] [poi(0).longitud] false ""

but I need it for an indeterminate number of n objects...

BeginJS
var n=-1
 //read a file with a json in each line and gets latitud, longitud y poiUrl.
 //bucle
n=n+1
 $App.poi[n].latitud=latitud;
 $App.poi[n].longitud=longitud;
 $App.poi[n].url=poiUrl;
 //fin de bucle 
EndJS 
jsAlert [poi(0).url] 
. draw a marker in map
neoMapAddMarker "Container2" "" "blue" [poi(0).latitud] [poi(0).longitud] false ""

Due to my mental confusion today with objects and arrays I don't see how to do it ;.-)

 

ok, I didn't remember $scope...

$App.n=n;
$scope.CreaObjetoVacio(n);
$App.poi[n].latitud=latitud;
$App.poi[n].longitud=longitud;
$App.poi[n].url=poiUrl;
$scope.pintapunto(n);

where:
CreaObjetovacio is a subroutine with:
CreateEmptyObject [poi([n])]
and:
pintapunto is a subroutine with:
neoMapAddMarker "Container2" "" "blue" [poi([n]).latitud] [poi([n]).longitud] false ""