我正在尝试实施树下拉选项。我能够显示我在数据库中的选项。但是点击它时没有被点击或发布。这就是我所做的。
我已从控制器发送数组数据,如下所示:
$this->data['category_tree'] = $this->general->get_category_tree();
一般的功能是:
public function get_category_tree()
{
$this->ci->db->where('is_display','1');
$query = $this->ci->db->get('product_categories');
if ($query->num_rows() > 0)
{
foreach($query->result() as $cat)
{
if($cat->parent_id=='0'){
//category
$categories_arr[$cat->id] = array('id' => $cat->id, 'parent_id'=>$cat->parent_id ,'name' => $cat->name, 'subcat' => array());
}else{
//subcategory;
$categories_arr[$cat->parent_id]['subcat'][] = array('id' => $cat->id, 'parent_id' => $cat->parent_id, 'name' => $cat->name);
}
}
return $categories_arr;
}
return false;
}
并且在视野中:
<fieldset >
<h4>Choose Category</h4>
<div class="ddmenu"> <a id="chooseCategory" href="javascript:void(0)" class="main_btn">
<?php if($this->input->post('categoryName',TRUE)){echo $this->input->post('categoryName',TRUE);}?>
</a>
<ul>
<?php
if($category_tree){
foreach($category_tree as $category)
{
?>
<li <?php if(!$category['subcat']){ ?> onclick="addThis('<?php echo $category['name']; ?>','<?php echo $category['id']; ?>','0')" <?php } else { ?>class="dropdown-submenu"<?php }?>> <a href="javascript:void(0)" tabindex="-1"><?php echo $category['name']; ?></a>
<?php if($category['subcat']){ ?>
<ul class="dropdown-menu" >
<?php foreach($category['subcat'] as $subcat){?>
<li onclick="addThis('<?php echo $subcat['name']; ?>','<?php echo $category['id']; ?>','<?php echo $subcat['id']; ?>')"> <a href="javascript:void(0)" data-clickable="data-clickable" tabindex="-1"> <?php echo $subcat['name']; ?> </a> </li>
<?php } ?>
</ul>
<?php } ?>
</li>
<?php
}
?>
</ul>
</div>
<?php } ?>
</fieldset>
我得到了这个观点
但是当我点击它时,没有任何反应。我怎样才能发布。我已经加载了脚本。这有问题吗?
答案 0 :(得分:0)
抱歉,我给了你错误的JS。我不想重新创建你的整个场景,所以我只是做了以下几点:
<?php
$name = 'cat';
$cat_id = 12;
$subcat_id = 11;
$subcat_name = 'Subcat';
?>
<ul>
<li onclick=location.href='<?php echo base_url() . $name . '/' . $cat_id . '/' . $subcat_id; ?>'>
<a href="javascript:;" data-clickable="data-clickable" tabindex="-1"> <?php echo $subcat_name; ?> </a>
</li>
</ul>
当然,您的设置略有不同,但您应该能够根据需要替换变量。这确实将我重定向到一个不存在但正确请求的页面。