How can I pass an array as a data option to javascript?
For example, I have the following in my template:
In my controller, I'm passing the following param:
In my js file I have the following:
However, when I console.log(this.options.myArray); I only see Array or null in the log. I think I need to encode the array via json, but json_encode doesn't seem to be a valid function in the template engine.
For example, I have the following in my template:
HTML:
data-my-array="{$myArray}"
In my controller, I'm passing the following param:
PHP:
$viewParams = ['myArray' => [0=>'moo', 1=>'moo1', 2=>'moo2']];
In my js file I have the following:
JavaScript:
options: {
myArray: null,
},
However, when I console.log(this.options.myArray); I only see Array or null in the log. I think I need to encode the array via json, but json_encode doesn't seem to be a valid function in the template engine.
Last edited: