B4J Question JavaScript Array to B4J Array

Nokia

Active Member
Licensed User
Longtime User
I'm having an issue with trying to get two JavaScript arrays and use them in B4J. This is the instructions I get form the site:

Array 1:
doc.getSelections(?lineSep: string) → array<string>Returns an array containing a string for each selection, representing the content of the selections.

Array 2:
doc.listSelections() → array<{anchor, head}>Retrieves a list of all current selections. These will always be sorted, and never overlap (overlapping selections are merged). Each object in the array contains anchor and head properties referring to {line, ch} objects.

JS Code:
JavaScript:
getSelections: function(lineSep) {
      var parts = [], ranges = this.sel.ranges;
      for (var i = 0; i < ranges.length; i++) {
        var sel = getBetween(this, ranges[i].from(), ranges[i].to());
        if (lineSep !== false) { sel = sel.join(lineSep || this.lineSeparator()); }
        parts[i] = sel;
      }
      return parts
    },
       
listSelections: function() { return this.sel.ranges },

I'm using this to get the javaobject

B4X:
Dim JSO As JavaObject = ExecuteScript($"editor.getSelections(",");"$)

Any idea how to use this in B4J?
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
JavaScript arrays are objects and are not compatible with b4j arrays.

but you can convert such arrays into JSON and parsed on the backend with:
 
Upvote 0
Top