我正在使用 jquery 手风琴来显示带有子项目的列表。我有一个类别表和产品表。我想将这些类别和相应的产品提取到列表中。在我的控制器中,我添加了以下代码。
$category=$this->Category->find('list',
array('fields'=>array('id','category_name')));
$this->set('category',$category);
$productlist=$this->Product->find('list',
array('fields'=>array('id','product_name','category_id')));
$this->set('productMenu',$productlist);
在我的列表中,我添加了列表值
<ul id="nav"><?php
foreach ($category as $key => $value)
{
?><li><a href="#"><?php echo $value; ?></a>
<ul class="sub">
<?php foreach ($productMenu as $key => $value )
{ ?>
<li><a href="#"><?php echo $value; ?></a>
<?php } ?>
</ul>
</li><?php
}
?></ul>
现在该类别显示良好,我没有得到添加属于特定类别的产品的逻辑。如果有人知道这一点,请帮助我。我卡住了。。
当我调试这个结果时,我也得到了结果
debug($catgory)
array(
(int) 1 => 'Crowns And Bridges Non Metal',
(int) 2 => 'Crowns And Bridges Metal',
(int) 3 => 'Implants',
(int) 4 => 'Dentures'
)
debug($product)
array(
(int) 1 => array(
(int) 1 => 'Lava',
(int) 2 => 'ZR Crown'
),
(int) 2 => array(
(int) 3 => 'Porcelain fused to metal crowns'
),
(int) 3 => array(
(int) 4 => 'General Restorative',
(int) 5 => 'Customised Abutments',
(int) 6 => 'Avinent Implants'
),
(int) 4 => array(
(int) 7 => 'Partial Dentures',
(int) 8 => 'Complete Dentures:'
)