客户反映:点击产品目录其中一个分类后自动返回到一级分类,要求实现点击后产品信息更新但目录结构不变,其实就是局部刷新功能。
解决:
两个方案
1.AJAX技术实现网页无闪自动局部刷新
2.直接用JS实现
下面就介绍用dTree来做
dTree优点有(作者的网站 http://destroydrop.com/javascripts/tree/)
1.无限级分类
2.可用于内嵌框架
3.自动记录状态(跳转页面后目录仍然保持最后状态不会还原成全部折叠)
4.可在一个页面上存在多个DTREE
5.支持所有常用浏览器
√Internet Explorer 5+
√Netscape 6+
√Opera 7+
√Mozilla FireFox
6.符合XHTML 1.0
7.可替换图片
修改cattree.lib.php标签(加粗部分为更改过),
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
<?php if(!defined('DEDEINC')) exit("Request Error!"); function lib_cattree(&$ctag,&$refObj) { global $dsql,$cfg_df_lang; //属性处理 //属性 showall 在空或不存在时,强制用产品模型id;如果是 yes 刚显示整个语言区栏目树;为其它数字则是这个数字的模型的id //typeid 指定顶级树 id ,指定后,前一个属性将无效 $attlist="showall|,catid|0"; FillAttsDefault($ctag->CAttribute->Items,$attlist); extract($ctag->CAttribute->Items, EXTR_SKIP); $revalue = '<div>'; $revalue .= '<script type="text/javascript">'; $revalue .= "d = new dTree('d');\n"; $lang = (isset($refObj->dtp->tplLang) ? $refObj->dtp->tplLang : $cfg_df_lang); if(empty($typeid)) { if( isset($refObj->TypeLink->TypeInfos['id']) ) { $typeid = $refObj->TypeLink->TypeInfos['id']; $reid = $refObj->TypeLink->TypeInfos['reid']; $topid = $refObj->TypeLink->TypeInfos['topid']; $lang = $refObj->TypeLink->TypeInfos['lang']; $channeltype = $refObj->TypeLink->TypeInfos['channeltype']; $ispart = $refObj->TypeLink->TypeInfos['ispart']; if($reid==0) $topid = $typeid; } else { $typeid = $reid = $topid = $channeltype = $ispart = 0; } } else { $row = $dsql->GetOne("Select reid,topid,lang,channeltype,ispart From <code>#@__arctype</code> where id='$typeid' "); if(!is_array($row)) { $typeid = $reid = $topid = $channeltype = $ispart = 0; } else { $reid = $row['reid']; $topid = $row['topid']; $lang = $row['lang']; $channeltype = $row['channeltype']; $ispart = $row['ispart']; } } if( !empty($catid) ) { $topQuery = "Select id,typename,typedir,isdefault,defaultname,ispart,namerule2 From <code>#@__arctype</code> where reid='$catid' And ishidden<>1 "; } else { if($showall == "yes" ) { $topQuery = "Select id,typename,typedir,isdefault,defaultname,ispart,namerule2 From <code>#@__arctype</code> where reid='$topid' "; } else { if($showall=='') { if( $ispart < 2 && !empty($channeltype) ) $showall = $channeltype; else $showall = 6; } $topQuery = "Select id,typename,typedir,isdefault,defaultname,ispart,namerule2 From <code>#@__arctype</code> where reid='{$topid}' And channeltype='{$showall}' And ispart<2 And ishidden<>1 "; } } $dsql->Execute('t', $topQuery); while($row = $dsql->GetArray('t')) { $row['typelink'] = GetTypeUrl($row['id'],MfTypedir($row['typedir']),$row['isdefault'],$row['defaultname'],$row['ispart'],$row['namerule2']); $revalue .= "d.add({$row['id']},-1,'{$row['typename']}','{$row['typelink']}');\n"; cattreeListSon($row['id'], $revalue); } $revalue .= "document.write(d);\n"; $revalue .= '</script>'; $revalue .= '</div>'; return $revalue; } function cattreeListSon($id, &$revalue) { global $dsql; $query = "Select id,typename,typedir,isdefault,defaultname,ispart,namerule2 From <code>#@__arctype</code> where reid='{$id}' And ishidden<>1 "; $dsql->Execute($id, $query); $thisv = ''; while($row = $dsql->GetArray($id)) { $row['typelink'] = GetTypeUrl($row['id'],MfTypedir($row['typedir']),$row['isdefault'],$row['defaultname'],$row['ispart'],$row['namerule2']); $revalue .= "d.add({$row['id']},{$id},'{$row['typename']}','{$row['typelink']}')\n"; cattreeListSon($row['id'], $revalue); } if($thisv!='') $revalue .= " <dd>\n$thisv </dd>\n"; } ?> |
效果:http://www.longwayauto.com/plus/list.php?tid=11
未经允许不得转载:Windy's Blog » 用dTree改造dedeeims产品目录