array( 'db_type' => 'mysql'.'db_user' => 'root'.'db_pwd' => ''.'db_host' => 'localhost'.'db_port' => '3306'.'db_name' => 'test'.'DB_PREFIX' => 'tp_'.// 數(shù)據(jù)庫表前綴 'DB_CHARSET'=> 'utf8'.// 字符集 'DB_DEBUG' => TRUE.// 數(shù)據(jù)庫調(diào)試模式 開啟后可以記錄SQL日志 3.2.3新增),。Common/function.php 遍歷函數(shù)loop。" />

<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        thinkphp實現(xiàn)無限分類(使用遞歸)_javascript技巧

        來源:懂視網(wǎng) 責編:小OO 時間:2020-11-27 21:47:35
        文檔

        thinkphp實現(xiàn)無限分類(使用遞歸)_javascript技巧

        數(shù)據(jù)庫:test;數(shù)據(jù)表:(tp_category)。Common/conf/config.php。'DB_CONFIG2' => array( 'db_type' => 'mysql'.'db_user' => 'root'.'db_pwd' => ''.'db_host' => 'localhost'.'db_port' => '3306'.'db_name' => 'test'.'DB_PREFIX' => 'tp_'.// 數(shù)據(jù)庫表前綴 'DB_CHARSET'=> 'utf8'.// 字符集 'DB_DEBUG' => TRUE.// 數(shù)據(jù)庫調(diào)試模式 開啟后可以記錄SQL日志 3.2.3新增),。Common/function.php 遍歷函數(shù)loop。
        推薦度:
        導(dǎo)讀數(shù)據(jù)庫:test;數(shù)據(jù)表:(tp_category)。Common/conf/config.php。'DB_CONFIG2' => array( 'db_type' => 'mysql'.'db_user' => 'root'.'db_pwd' => ''.'db_host' => 'localhost'.'db_port' => '3306'.'db_name' => 'test'.'DB_PREFIX' => 'tp_'.// 數(shù)據(jù)庫表前綴 'DB_CHARSET'=> 'utf8'.// 字符集 'DB_DEBUG' => TRUE.// 數(shù)據(jù)庫調(diào)試模式 開啟后可以記錄SQL日志 3.2.3新增),。Common/function.php 遍歷函數(shù)loop。
        本文實例為大家分享了thinkphp實現(xiàn)無限分類的詳細代碼,希望對大家學習無限分類有所啟發(fā)。

        數(shù)據(jù)庫:test
        數(shù)據(jù)表:(tp_category):


        Common/conf/config.php

        'DB_CONFIG2' => array(
         'db_type' => 'mysql',
         'db_user' => 'root',
         'db_pwd' => '',
         'db_host' => 'localhost',
         'db_port' => '3306',
         'db_name' => 'test',
         'DB_PREFIX' => 'tp_', // 數(shù)據(jù)庫表前綴
         'DB_CHARSET'=> 'utf8', // 字符集
         'DB_DEBUG' => TRUE, // 數(shù)據(jù)庫調(diào)試模式 開啟后可以記錄SQL日志 3.2.3新增
        ),
        

        Common/function.php 遍歷函數(shù)loop

        /*
         * 遞歸遍歷
         * @param $data array
         * @param $id int
         * return array
         * */
        function recursion($data, $id=0) {
         $list = array();
         foreach($data as $v) {
         if($v['pid'] == $id) {
         $v['son'] = recursion($data, $v['id']);
         if(empty($v['son'])) {
         unset($v['son']);
         }
         array_push($list, $v);
         }
         }
         return $list;
        }
        

        Controller/IndexController.class.php

        public function test() {
         $category = M('category', '', C('DB_CONFIG2'))->select();
         $result = loop($category);
         var_dump($result);
         $this->assign('list', $result);
         $this->display();
        }
        

        在模板(View/Index/test.html)中輸出(僅支持2級分類,如果想全部顯示,建議先把數(shù)組轉(zhuǎn)換成JSON格式,然后通過AJAX請求,JS生成)

        
         
         
      1. {$vo.category}
      2. {$cate.category}
      3. 后續(xù)(ajax請求,遞歸顯示所有分類):

        方法 Controller/IndexController.class.php

        public function test() {
         $this->display();
        }
        
        public function resultCategory() {
         $category = M('category', '', C('DB_CONFIG2'))->select();
         $result = loop($category);
         $this->ajaxReturn(array('data'=>$result,'status'=>'1','info'=>'獲取列表成功'));
        }
        
        

        模板View/Index/test.html

        
        
        
         
         分類測試
         

        JS遞歸(特殊):

        這個函數(shù)相當于實現(xiàn)php的str_repeat函數(shù)

        /* 字符串重復(fù)函數(shù) */
        if(!String.str_out_times) {
         String.prototype.str_out_times = function(l) {
         return new Array(l+1).join(this);
         }
        }
        
        // 定位到當前選擇
        function recursion(selector, data, j, pid) {
         var space = ' ┠ ';
         if(!data) return false;
         $.each(data, function(i, item) {
         var opt = $('');selector.append(opt);
         if(item.son && (item.son).length>0) {
         recursion(selector, item.son, ++j);
         j=0; 
         }
         });
        
         // 當前是哪個分類
         selector.find('option').each(function() {
         if($(this).val() == pid) {
         $(this).attr('selected', 'selected');
         }
         });
        }
        
        

        為什么j=0呢。因為執(zhí)行順序感覺與php不同,這里是從上到下加載。

        ajax請求數(shù)據(jù):

        $('.btn-edit').click(function() {
         var id = $(this).data('id');
         $.post("{:U('Article/editArticle')}", {id: id}, function(res) {
        
         // 分類
         $('[name="pid"]').html('');
         recursion($('[name="pid"]'), res.sort, 0, res.pid);
        
         $('[name="id"]').val(res.id);
         $('[name="title"]').val(res.title);
         $('[name="summary"]').val(res.summary);
         $('#thumbnailImg').attr('src', "__UPLOAD__"+'/thumbnail/'+res.thumbnail);
         ue.setContent(res.content);
        
         $('#modal-edit').modal('show');
         });
        });
        

        聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        thinkphp實現(xiàn)無限分類(使用遞歸)_javascript技巧

        數(shù)據(jù)庫:test;數(shù)據(jù)表:(tp_category)。Common/conf/config.php。'DB_CONFIG2' => array( 'db_type' => 'mysql'.'db_user' => 'root'.'db_pwd' => ''.'db_host' => 'localhost'.'db_port' => '3306'.'db_name' => 'test'.'DB_PREFIX' => 'tp_'.// 數(shù)據(jù)庫表前綴 'DB_CHARSET'=> 'utf8'.// 字符集 'DB_DEBUG' => TRUE.// 數(shù)據(jù)庫調(diào)試模式 開啟后可以記錄SQL日志 3.2.3新增),。Common/function.php 遍歷函數(shù)loop。
        推薦度:
        標簽: 分類 php 無限
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 亚洲精品一级无码鲁丝片| 成人性生交大片免费看无遮挡 | 亚洲乱妇老熟女爽到高潮的片| 久久久久国产精品免费免费不卡 | 久久久久免费看黄a级试看| 自拍偷自拍亚洲精品被多人伦好爽| 男性gay黄免费网站| 亚洲精品成人区在线观看| 九九热久久免费视频| 亚洲精品国产精品乱码不99| 在线观看免费视频一区| 亚洲AV无码国产精品麻豆天美 | 免费看国产成年无码AV片| 亚洲av无码国产综合专区| 亚洲免费综合色在线视频| 亚洲色偷偷综合亚洲av78| 亚洲一区二区三区日本久久九| 亚洲av永久无码嘿嘿嘿| 成人免费无码视频在线网站| 亚洲熟妇成人精品一区| 免费成人av电影| 中国极品美軳免费观看| 亚洲精品福利在线观看| 无码国产精品久久一区免费| 久久久亚洲精华液精华液精华液| 亚洲综合激情另类专区| 国产午夜精品久久久久免费视| 亚洲国产美女在线观看| 日本不卡免费新一二三区| 国产精品美女久久久免费 | 中文字幕免费观看| 亚洲国产乱码最新视频| 亚洲伊人久久成综合人影院| 三年片在线观看免费观看大全一 | 久久久久久国产精品免费免费男同 | 国产亚洲综合久久| 亚洲精品国偷自产在线| 国国内清清草原免费视频99| 黄色免费网址大全| 最好免费观看韩国+日本| 免费一级毛片在线播放放视频 |