Is it possible to send an nested array from ruby to js using HtmlDialog.execute_script?
Or I have to contrive something using json?

Nested arrays are a subset of JSON, so yes.
You can send anything (any type of object) to an HtmlDialog, under the condition that the execute_script method accepts only a valid string of JavaScript code. So the data must be serialized as string and parsable as valid JavaScript.

See these post for some ideas …

So basically … from the Ruby-side …

my_ary = [[1,2,3],[4,5,6],[7,8,9]]
html_dlg.execute_script("Data = JSON.parse('#{my_ary.to_json}');")

… and afterward Data is a JS reference for a nested JS array.

The caveat is that all the objects in the nested array must be convertible to string via: #to_json.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.