I have an array of objects in my Javascript file that I need to access from js_of_ocaml. I've come up with this so far:
let table_decks = (Js.Unsafe.variable "table_decks" :>
< deck_nr : int > Js.js_array Js.t)
In Javascript, the array will be like table_decks = {{deck_nr: 10, ...}, {deck_nr: 20, ...}}
with more fields than just deck_nr
.
My question is: How do I access this array? I find a lot of functions in Js.js_array
, but no get/set.
(Another question is if the coerce is in fact correct?)
Use Js.array_get/array_set or Js.Unsafe.get/set.
To support overloading on ocaml, js_of_ocaml removes letters after last _ in javascript name. So "deck_nr" becames "deck" in generated js, so add another "_".
Put all it together...