如何制作“ Tree Dropdown”在codeigniter中? [英] How to make "Tree Dropdown" in codeigniter?

查看:51
本文介绍了如何制作“ Tree Dropdown”在codeigniter中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现树下拉选项。我能够显示数据库中的选项。但是单击时不会被单击或发布。这是我所做的。

I am trying to implement tree dropdown option. I am being able to show options that i have in my database. But when clicked it is not being clicked or posted. Here is what i have done.

我已经从控制器发送了数组数据,如下所示:

I have send array data from controller like this:

    $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>

我得到这个视图

但是当我单击它时,什么也没有发生。我如何将其发布。我已经加载了脚本。

But when I click it, nothing happens. How can I make it posted. I have loaded the script. Is it problem with it?

推荐答案

对不起,我给你错了JS。我不想重新创建整个方案,所以我只做了以下工作:

Sorry, I gave you the wrong JS. I didn't want to recreate your entire scenario, so I just did the following:

<?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>

当然,您的设置略有不同,但是您应该能够适当地替换变量。这确实将我重定向到了一个不存在但正确请求的页面。

Of course, your setup is slightly different, but you should be able to replace the variables as appropriate. This did redirect me to a non-existent, but correctly requested page.

这篇关于如何制作“ Tree Dropdown”在codeigniter中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆