Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I created a twig array and populated it with objects, and i want to parse that to an javascript array and objects

Twig array:

itm = array:1 [
  0 => array:2 [
    "Test1" => "Testtt1"
    "Test2" => "Testtt2"
  ]
]

I tried to parse it like this but it return and empty array:

var arrAll = [];
 arrAll = {{ itm|json_encode }} 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
141 views
Welcome To Ask or Share your Answers For Others

1 Answer

You have to get the raw variable, otherwise it will fail:

 var arrAll = [];
 arrAll = {{ itm|json_encode|raw }} 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...