How can I pass an array as a data option to javascript?
For example, I have the following in my template:
HTML:
In my controller, I'm passing the following param:
PHP:
In my js file I have the following:
JavaScript:
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...
Read more
Читать далее...
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...
Read more
Читать далее...