Twig数组充满了对象到Javascript数组

Twig数组充满了对象到Javascript数组

本文介绍了Twig数组充满了对象到Javascript数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个树枝数组,并在其中填充了对象,我想将其解析为javascript数组和对象

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

细枝阵列:

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 }}

推荐答案

您必须获取raw变量,否则它将失败:

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

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

这篇关于Twig数组充满了对象到Javascript数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 09:09