Example #1
0
/**
 * 表单调用联动菜单
 * @param $linkageid 联动菜单id
 * @param $id 生成联动菜单的样式id
 * @param $defaultvalue 默认值
 * @param $level 级数
 * required 必填
 */
function linkageform($linkageid = 0, $defaultvalue = 0, $id = 'linkage', $level = 3, $required)
{
    $data = get_linkage_data();
    $datas = $data[$linkageid];
    $infos = $datas['data'];
    if (!defined('FINECMS_LINKAGE_INIT_LD')) {
        define('FINECMS_LINKAGE_INIT_LD', 1);
        $string .= '<script type="text/javascript" src="' . ADMIN_THEME . 'js/jquery.ld.js"></script>';
    }
    $default_txt = '';
    $default_lev = 1;
    if ($defaultvalue) {
        $default_txt = menu_linkage_level($defaultvalue, $linkageid, $infos);
        $default_lev = substr_count($default_txt, ' > ');
        $default_txt = '["' . str_replace(' > ', '","', $default_txt) . '"]';
    }
    $string .= $defaultvalue ? '<input type="hidden" name="data[' . $id . ']"  id="fc_' . $id . '" value="' . $defaultvalue . '">' : '<input type="hidden" name="data[' . $id . ']"  id="fc_' . $id . '" value="">';
    for ($i = 1; $i <= $level; $i++) {
        $style = $i > $default_lev ? 'style="display:none"' : '';
        $required = $i == 1 && $required ? ' required' : '';
        $string .= '<select class="finecms-select-' . $id . '" name="' . $id . '-' . $i . '" id="' . $id . '-' . $i . '" width="100" ' . $style . $required . '><option value=""> -- </option></select>&nbsp;&nbsp;';
    }
    $string .= '<script type="text/javascript">
				$(function(){
					var $ld5 = $(".finecms-select-' . $id . '");					  
					$ld5.ld({ajaxOptions:{"url":"' . SITE_URL . 'index.php?c=api&a=linkage&id=' . $linkageid . '"},defaultParentId:0})	 
					var ld5_api = $ld5.ld("api");
					ld5_api.selected(' . $default_txt . ');
					$ld5.bind("change",onchange);
					function onchange(e){
						var $target = $(e.target);
						var index = $ld5.index($target);
						$("#fc_' . $id . '-' . $i . '").remove();
						$("#fc_' . $id . '").val($ld5.eq(index).show().val());
						index ++;
						$ld5.eq(index).show();
					}
				})
	</script>';
    return $string;
}
Example #2
0
 /**
  * 联动菜单数据
  */
 public function linkageAction()
 {
     $keyid = (int) $this->get('id');
     $parentid = (int) $this->get('parent_id');
     $linkage = get_linkage_data();
     $infos = $linkage[$keyid]['data'];
     $json = array();
     foreach ($infos as $k => $v) {
         if ($v['parentid'] == $parentid) {
             $json[] = array('region_id' => $v['id'], 'region_name' => $v['name']);
         }
     }
     echo json_encode($json);
 }