本帖最后由 泡哥 于 2013-2-13 01:17 编辑
discuz的地区下拉菜单是通过showdistrict函数实现的
其中有个参数$showlevel 按字面解释显示联动级数
./source/function/function_profile.php 333~384行
在函数中- function showdistrict($values, $elems=array(), $container='districtbox', $showlevel=null, $containertype = 'birth') {
- $html = '';
- if(!preg_match("/^[A-Za-z0-9_]+$/", $container)) {
- return $html;
- }
- // $showlevel 不为空 那么显示设定级数 否则统计数组元素个数
- $showlevel = !empty($showlevel) ? intval($showlevel) : count($values);
- // $showlevel 必须是1~4
- $showlevel = $showlevel <= 4 ? $showlevel : 4;
复制代码- for($i=0;$i<$showlevel;$i++) {
- $level = $i+1;
- if(!empty($options[$level])) {
- $jscall = "showdistrict('$container', ['$elems[0]', '$elems[1]', '$elems[2]', '$elems[3]'], $showlevel, $level, '$containertype')";
- $html .= '<select name="'.$elems[$i].'" id="'.$elems[$i].'" class="ps" onchange="'.$jscall.'" tabindex="1">';
- $html .= '<option value="">'.lang('spacecp', 'district_level_'.$level).'</option>';
- foreach($options[$level] as $option) {
- $selected = $option[0] == $values[$i] ? ' selected="selected"' : '';
- $html .= '<option did="'.$option[0].'" value="'.$option[1].'"'.$selected.'>'.$option[1].'</option>';
- }
- $html .= '</select>';
- $html .= ' ';
- }
- }
- return $html;
- }
复制代码 计数器通过$showlevel 控制几级联动
很明显showdistrict函数中$showlevel参数是应该控制联动级数的
设定$showlevel为2 那么就是省市级联动
而在./source/include/spacecp/spacecp_search.php中- include_once libfile('function/profile');
- //$birthcityhtml采用的调用是设定2级、2个元素
- $birthcityhtml = showdistrict(array(0,0), array('birthprovince', 'birthcity'), 'birthcitybox', null, 'birth');
- $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传递参数问题
|