溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

使用thinkphp框架怎么實(shí)現(xiàn)一個(gè)無(wú)限級(jí)欄目的排序功能

發(fā)布時(shí)間:2021-04-16 16:24:42 來(lái)源:億速云 閱讀:179 作者:Leah 欄目:開(kāi)發(fā)技術(shù)

本篇文章為大家展示了使用thinkphp框架怎么實(shí)現(xiàn)一個(gè)無(wú)限級(jí)欄目的排序功能,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過(guò)這篇文章的詳細(xì)介紹希望你能有所收獲。

數(shù)據(jù)表結(jié)構(gòu)

使用thinkphp框架怎么實(shí)現(xiàn)一個(gè)無(wú)限級(jí)欄目的排序功能

<form method="post" action="">
<table class="table table-bordered table-hover">
<thead class="">
<tr>
<th width="6%" class="text-center">ID</th>
<th width="6%" class="text-center">pid</th>
<th width="8%" class="text-center">排序</th>
<th>欄目名稱(chēng)</th>
<th width="16%" class="text-center">操作</th>
</tr>
</thead>
<tbody>
<volist name="cateRes" id="cate">
<tr>
<td align="center">{$cate.id}</td>
<td align="center">{$cate.pid}</td>
<td align="center">
<input type="text" name="sort[{$cate.id}]" value="{$cate.sort}" /></td>
<td><?php echo str_repeat('-', $cate['level']*8);?>{$cate.cate_name}</td>
<td align="center">
<a href="" class=" rel="external nofollow" btn btn-primary btn-sm shiny">
<i class="fa fa-edit"></i> 編輯
</a>
<a href="#" rel="external nofollow" onClick="warning('確實(shí)要?jiǎng)h除嗎', ”)" class="btn btn-danger btn-sm shiny">
<i class="fa fa-trash-o"></i> 刪除
</a>
</td>
</tr>
</volist>
<tr>
<td colspan="4">
<button type="button" tooltip="排序"  class="btn btn-sm btn-azure btn-addon">排序</button>
</td>
</tr>
</tbody>
</table>
</form>

上面的代碼我們可以看出整個(gè)table是用form包裹的,因?yàn)槲覀円峤慌判蜃侄危孕枰韱巍?/p>

我們實(shí)現(xiàn)無(wú)限極欄目排序的核心代碼:

<input type="text" name="sort[{$cate.id}]" value="{$cate.sort}" />

就是這一句,實(shí)際上我們是拼裝了一個(gè)sort[]數(shù)組,整個(gè)數(shù)組的每個(gè)元素的鍵是當(dāng)前欄目的id而值是當(dāng)前欄目的排序的值,這樣我們一旦提交數(shù)組就可以根據(jù)id修改sort了

完整代碼:

public function lst(){
$cate=D('Cate');
if(IS_POST){//排序
$data=I('sort');
foreach ($data as $k => $v) {
$cate->where(array('id'=>$k))->save(['sort'=>$v]);
}
return;
}
$cateRes=$cate->cateTree();//無(wú)限級(jí)分類(lèi)樹(shù)
$this->assign([
'cateRes'=>$cateRes,
]);
$this->display('list');
}

上述內(nèi)容就是使用thinkphp框架怎么實(shí)現(xiàn)一個(gè)無(wú)限級(jí)欄目的排序功能,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI