ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
### 从性别到小类的筛选条件封装 **位置:** Application\Common\View\category.html **控制器调用:** 所属模块控制判断分类和接收参数 ~~~ // 大类、中类和小类搜索条件显示 if (!empty($params['large_class'])) { $parent_id = M('goods_category')->field('parent_id')->where(array('id' => $params['large_class']))->find(); $data_a = $this->get_category($parent_id['parent_id']); $this->assign('data_a', $data_a); $data_b = $this->get_category($params['large_class']); $this->assign('data_b', $data_b); } if (!empty($params['middle_class'])) { $parent_id = M('goods_category')->field('parent_id')->where(array('id' => $params['middle_class']))->find(); $data_b = $this->get_category($parent_id['parent_id']); $this->assign('data_b', $data_b); $data_c = $this->get_category($params['middle_class']); $this->assign('data_c', $data_c); } if (!empty($params['small_class'])) { $parent_id = M('goods_category')->field('parent_id')->where(array('id' => $params['small_class']))->find(); $data_c = $this->get_category($parent_id['parent_id']); $this->assign('data_c', $data_c); } ~~~ ~~~ // 获取分类 public function get_small_category() { $cat_id = I('param.cat_id'); if ($cat_id) { $cat_list = $this->get_category($cat_id); $this->ajaxReturn($cat_list); } } ~~~ **搜索条件代码:** 封装 category.html 文件: ~~~ <script charset="UTF-8" src="__PUBLIC__/base/js/category.js"></script> <select class="form-control" style="width:172px;" name="sex_class" id="sex_class"> <option value="">类别</option> <volist name="sexCat" id="vo"> <option value="{$vo.id}" <if condition="$params['sex_class'] eq $vo['id']"> selected </if>>{$vo.cat_name}</option> </volist> </select> <select class="form-control" style="width:172px;" name="large_class" id="large_class"> <option value="">大类</option> <if condition="$data_a"> <volist name="data_a" id="vo"> <option value="{$vo.id}" <if condition="$vo['id'] eq $params['large_class']"> selected </if>>{$vo.cat_name}</option> </volist> </if> </select> <select class="form-control" style="width:172px;" name="middle_class" id="middle_class"> <option value="">中类</option> <if condition="$data_b"> <volist name="data_b" id="vo"> <option value="{$vo.id}" <if condition="$vo['id'] eq $params['middle_class']">selected</if>>{$vo.cat_name}</option> </volist> </if> </select> <select class="form-control" style="width:172px;" name="small_class" id="small_class"> <option value="">小类</option> <if condition="$data_c"> <volist name="data_c" id="vo"> <option value="{$vo.id}" <if condition="$vo['id'] eq $params['small_class']">selected</if>>{$vo.cat_name}</option> </volist> </if> </select> ~~~ View Form 搜索条件中调用: ~~~ <include file="./Application/Common/View/category.html" /> ~~~