树枝为循环阵列键

时间:2018-12-11 00:45:19

标签: twig

我是树枝的新手,在for循环中遇到了一些问题。     For循环如何获取密钥

{% set data = {pounds: {all: {year: {2012: 123,2013:234,2014:500}}}} %}
{% set i = {0:2012,1:2013,2:2014} %}
{% for years,value in data.millions.all %}
  {% for key,val in i %}
   {{ value.val }}
  {% endfor %}
{% endfor %}

执行后,我遇到以下错误

#1    Type    Twig_Error_Runtime
#2    Message    Key "val" for array with keys "2012, 2013, 2014" does not exist.
#3    At    twigfiddle:environment/KGoFPP6aiGA8cNzG/twig/main.twig:5

预期产量

123
234
500

Ref:https://twigfiddle.com/1c6rsv

感谢您的帮助

0 个答案:

没有答案