Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

[求助] 地区函数 $showlevel 参数怎么控制联动级数

[复制链接]
泡哥 发表于 2013-2-13 00:50:08 | 显示全部楼层 |阅读模式
本帖最后由 泡哥 于 2013-2-13 01:17 编辑

discuz的地区下拉菜单是通过showdistrict函数实现的
其中有个参数$showlevel 按字面解释显示联动级数

./source/function/function_profile.php  333~384行

在函数中
  1. function showdistrict($values, $elems=array(), $container='districtbox', $showlevel=null, $containertype = 'birth') {
  2.         $html = '';
  3.         if(!preg_match("/^[A-Za-z0-9_]+$/", $container)) {
  4.                 return $html;
  5.         }
  6.        // $showlevel 不为空 那么显示设定级数 否则统计数组元素个数
  7.         $showlevel = !empty($showlevel) ? intval($showlevel) : count($values);
  8.       // $showlevel 必须是1~4
  9.         $showlevel = $showlevel <= 4 ? $showlevel : 4;
复制代码
  1. for($i=0;$i<$showlevel;$i++) {
  2.                 $level = $i+1;
  3.                 if(!empty($options[$level])) {
  4.                         $jscall = "showdistrict('$container', ['$elems[0]', '$elems[1]', '$elems[2]', '$elems[3]'], $showlevel, $level, '$containertype')";
  5.                         $html .= '<select name="'.$elems[$i].'" id="'.$elems[$i].'" class="ps" onchange="'.$jscall.'" tabindex="1">';
  6.                         $html .= '<option value="">'.lang('spacecp', 'district_level_'.$level).'</option>';
  7.                         foreach($options[$level] as $option) {
  8.                                 $selected = $option[0] == $values[$i] ? ' selected="selected"' : '';
  9.                                 $html .= '<option did="'.$option[0].'" value="'.$option[1].'"'.$selected.'>'.$option[1].'</option>';
  10.                         }
  11.                         $html .= '</select>';
  12.                         $html .= '  ';
  13.                 }
  14.         }
  15.         return $html;
  16. }
复制代码
计数器通过$showlevel 控制几级联动
很明显showdistrict函数中$showlevel参数是应该控制联动级数的
设定$showlevel为2 那么就是省市级联动

而在./source/include/spacecp/spacecp_search.php中
  1. include_once libfile('function/profile');
  2. //$birthcityhtml采用的调用是设定2级、2个元素
  3. $birthcityhtml = showdistrict(array(0,0), array('birthprovince', 'birthcity'), 'birthcitybox', null, 'birth');
  4. $residecityhtml = showdistrict(array(0,0, 0, 0), array('resideprovince', 'residecity', 'residedist', 'residecommunity'), 'residecitybox', null, 'reside');
复制代码
我的理解源代码是想出生地二级联动,但是$showlevel还是null空 没设定级数

但是实际操作依然是4级联动
totallevel   changelevel
    2              1
    2              2
当点击第二个下拉菜单时 还是产生 3级菜单
    3               1
    3               2
    3               3
查了半天没搞清楚 到底是js ajax传送错误 还是./source/include/misc/misc_ajax.php传递参数问题

仙居杨梅 发表于 2013-2-13 00:57:13 | 显示全部楼层
泡哥,dz前辈,很近不见了哦!
回复

使用道具 举报

 楼主| 泡哥 发表于 2013-2-16 08:11:55 | 显示全部楼层
自己顶,地区二级联动怎么写?
回复

使用道具 举报

要命的酒鬼 发表于 2013-2-17 03:08:01 | 显示全部楼层
DZ的程序没有错,$showlevel=$level,而$level是变化的,因此$showlevel也是变化的。
DZ原意就是设置了四级联动,因此不存在利用$showlevel参数来达到固定N级联动。
要想固定为只能N级联动,也很简单,为了不影响系统升级,复制showdistrict函数为自己的函数,然后将其中的4修改为你需要的数字(一定要0<N≤4),然后在你的程序中使用这个函数就OK了。

评分

1

查看全部评分

回复

使用道具 举报

 楼主| 泡哥 发表于 2013-2-17 08:41:10 | 显示全部楼层
要命的酒鬼 发表于 2013-2-17 03:08
DZ的程序没有错,$showlevel=$level,而$level是变化的,因此$showlevel也是变化的。
DZ原意就是设置了四级 ...

恩 谢谢酒鬼 你这个方法比css遮蔽容器长度有效!
回复

使用道具 举报

yao_512 发表于 2013-5-21 18:14:22 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2024-9-22 14:24 , Processed in 0.126506 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表