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
        主站蜘蛛池模板: 大香人蕉免费视频75| 亚洲美女免费视频| 亚洲精品偷拍视频免费观看| 大桥未久亚洲无av码在线| 成年女人毛片免费视频| 亚洲精品国产suv一区88| 国产高清免费的视频| 国产亚洲欧美日韩亚洲中文色| 国产jizzjizz视频免费看| 日韩在线一区二区三区免费视频 | 亚洲欧洲日本在线| 国产精品永久免费| 亚洲精品乱码久久久久久久久久久久| 黄 色一级 成 人网站免费| 精品亚洲综合在线第一区| 日本免费大黄在线观看| 国产成人精品日本亚洲专区6| 在线观看人成视频免费| 成人a毛片免费视频观看| 国产亚洲精品一品区99热| 在线观看的免费网站无遮挡| va天堂va亚洲va影视中文字幕 | 亚洲人成网亚洲欧洲无码| 日韩视频免费一区二区三区| 青青视频免费在线| 久久被窝电影亚洲爽爽爽| 国产人成免费视频网站| 久久久久亚洲国产AV麻豆| 亚洲一区二区女搞男| 1000部啪啪毛片免费看| 亚洲av日韩av永久在线观看| 亚洲综合色视频在线观看| 一级毛片在线免费看| 亚洲熟妇无码AV| 亚洲午夜久久久影院| 99久久精品日本一区二区免费| 国产精品亚洲一区二区三区在线观看| 亚洲精品无码不卡在线播放HE| 亚色九九九全国免费视频| 亚洲免费日韩无码系列| 亚洲一级毛片中文字幕|