我有3个实体
我通过加入这些表来获取数据
Group-SubGroup(OneToMany)
和Product-SubGroup(ManyToMany)
数据:
+---------------+------------+----------+
| Group | Subgroup | Product |
+---------------+------------+----------+
| Food | Fruits | Apple |
| Food | Fruits | Orange |
| Food | Vegetables | Brinjal |
| Food | Vegetables | Onion |
| Food | Vegetables | Potato |
| Food | Vegetables | Zucchini |
| Clothes | Men | Jeans |
| Clothes | Men | Shirts |
| Clothes | Women | Jeans |
| Clothes | Women | Skirt |
+---------------+------------+----------+
我想要实现的是使用树枝的树状结构
Group
Subgroup
Product
Group
Subgroup
Product
Product
Group
Subgroup
Product
Product
Product
任何想法我怎样才能在树枝上实现这一目标{i here但是我不明白...... ??
答案 0 :(得分:0)
嗯,我想你可以这样运行它(如果我做对了)
{% for group in groups %}
{% for subgroup in group.subgroups %}
{% for product in subgroup.products %}
// display your products
{% endfor %}
{% endfor %}
{% endfor %}