简体   繁体   English

试图获取非对象的属性“变量”

[英]Trying to get property 'variable' of non-object

Below is my Array (nationalNewArray)下面是我的数组(nationalNewArray)

    {   
        "Standard 1": {
                    "top10": "0",
                    "top50": "0",
                    "top100": "0",
                    "other": "0",
                    "top10_single": "0",
                    "top50_single": "0",
                    "top100_single": "0",
                    "other_single": "0"   },   
            "Standard 2": {
                    "top10": "0",
                    "top50": "0",
                    "top100": "0",
                    "other": "0",
                    "top10_single": "0",
                    "top50_single": "0",
                    "top100_single": "0",
                    "other_single": "0"   },   
            "Standard 3": {
                    "top10": "0",
                    "top50": "1",
                    "top100": "0",
                    "other": "1",
                    "top10_single": "0",
                    "top50_single": "0",
                    "top100_single": "1",
                    "other_single": "1"   },   
            "Standard 4": {
                    "top10": "0",
                    "top50": "0",
                    "top100": "0",
                    "other": "0",
                    "top10_single": "0",
                    "top50_single": "0",
                    "top100_single": "0",
                    "other_single": "0"   },   
            "Standard 5": {
                    "top10": "0",
                    "top50": "0",
                    "top100": "0",
                    "other": "0",
                    "top10_single": "0",
                    "top50_single": "0",
                    "top100_single": "1",
                    "other_single": "1"   },   
            "Standard 6": {
                    "top10": "1",
                    "top50": "0",
                    "top100": "0",
                    "other": "0",
                    "top10_single": "2",
                    "top50_single": "1",
                    "top100_single": "0",
                    "other_single": "1"   } 
}

above is my array,上面是我的数组,

                        {% for array in nationalNewArray %}

                        <tr>
                            <td>{{ array.level }}</td>
                            <td>{{ array.top10 }}</td>
                            <td>{{ array.top10_single }}</td>
                            <td>{{ array.newtop100 }}</td>
                            <td>{{ array.top100_single }}</td>
                        </tr>
                    {% endfor %}

above is my code in twig (view page), but when it always shows: Trying to get property 'variable' of non-object (twig).以上是我在 twig(查看页面)中的代码,但是当它总是显示:尝试获取非对象(树枝)的属性“变量”时。 any idea why the error appear?知道为什么会出现错误吗? shouldn't it able to access the data using for loop?它不应该能够使用 for 循环访问数据吗?

i tried different method does not work also ( with key )我尝试了不同的方法也不起作用(带键)

                        {% for key, array in nationalNewArray %}
                        <tr>
                            <td>{{ key }}</td>
                            <td>{{ array['top10'] }}</td>
                            <td>{{ array['top10_single'] }}</td>
                            <td>{{ array['newtop100'] }}</td>
                            <td>{{ array['top100_single'] }}</td>
                        </tr>
                        {% endfor %}

this helped me, look like i need to add 'key' and it show the data that i wanted and no more errors这对我有帮助,看起来我需要添加“密钥”,它显示了我想要的数据并且没有更多错误

https://twig.symfony.com/doc/3.x/tags/for.html https://twig.symfony.com/doc/3.x/tags/for.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM