Rails 3 passing a rails array to javascript function which uses a javascript array

前端 未结 5 855
悲哀的现实
悲哀的现实 2021-02-18 18:12

I am trying to pass a rails array to a javascript function. The function will then use the array values in javascript so I need to keep it an array.

Here is how I am

5条回答
  •  孤城傲影
    2021-02-18 18:49

    bokor's answer works, but causes some linter and IDE errors if you want the array to be saved to a const, instead of a var / let.

    The following variation seems to work and be compliant with the linters and IDEs that I am using.

    const js_array = JSON.parse('<%= raw @object %>');

提交回复
热议问题