久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何使 CakePHP 的 HABTM 復(fù)選框按字母順序排列在列

How to make CakePHP#39;s HABTM checkboxes alphabetical top to bottom in columns(如何使 CakePHP 的 HABTM 復(fù)選框按字母順序排列在列中)
本文介紹了如何使 CakePHP 的 HABTM 復(fù)選框按字母順序排列在列中的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我有餐廳菜系列表 (HABTM) - 當(dāng)用戶添加餐廳時(shí),他們會從所有菜系復(fù)選框中進(jìn)行選擇.

I have list of restaurant cuisines (HABTM) - when the user adds a restaurant, they choose from all the checkboxes of cuisines.

復(fù)選框輸入設(shè)置為 float:left;帶有填充/邊距......等等,一切看起來都不錯(cuò) - 一個(gè)漂亮的復(fù)選框網(wǎng)格.

The checkbox inputs are set to float:left; with padding/margins... etc and all looks good - a nice grid of checkboxes.

問題/問題:復(fù)選框按字母順序顯示,但與用戶期望的方式不同 - 它們在重復(fù)行中從左到右排列(就像您希望將它們?nèi)扛右粯?.

Question/Problem: The checkboxes show up alphabetically, but not in the way a user would expect - they're left to right in repeating rows (like you'd expect by making them all float).

我怎樣才能讓它們按字母順序排列,但在垂直列中?所以按字母順序,你會閱讀從上到下,然后轉(zhuǎn)到下一列.

How can I get them to be alphabetical, but in vertical columns? So alphabetically, you'd read Top to Bottom, then go to the next column.

我可以只找到普通的 PHP 就可以做到這一點(diǎn),但是在 CakePHP 中,我顯示復(fù)選框的調(diào)用只是:

I could do this just find w/ just normal PHP, but in CakePHP, my call to show the checkboxes is just:

<?php echo $this->Form->input('RestaurantCuisine', array('multiple'=>'checkbox')); ?>

補(bǔ)充:

JS FIDDLE HERE(html 大多不可編輯因?yàn)樗怯?CakePHP 生成的 - 如果需要,可以編輯 CakePHP 回聲 - 但這不能在小提琴中)

JS FIDDLE HERE (html is mostly un-editable since it's being generated by CakePHP - can edit the CakePHP echo though if needed - but that can't be in the fiddle)

推薦答案

根據(jù)評論,我創(chuàng)建了一個(gè)有望被接受的 jQuery 解決方案.

Based on the comments, I've created a hopefully acceptable jQuery solution.

參見: http://jsfiddle.net/svRmL/

var $element = $('#cuisines');
var $elementWidth = $element.find(' > .checkbox').outerWidth(true),
    elementCount = $element.find(' > .checkbox').length,
    $boxes = $element.find(' > .checkbox');

/* just for debug */
$boxes.each(function(i) {
    $(this).find('label').html(i);
});

//set resize function
$(window).resize(function() {
    var perRow = Math.floor($element.width() / $elementWidth),
        i, j, $thisColumn, inc;

    $boxes.appendTo($element); //move elements out of columns from previous resize
    $('.tempColumn').remove(); //destroy old columns
    for (i = 0; i < perRow; i++) {
        $thisColumn = $('<div class="tempColumn" />').appendTo($element).css({
            width: $elementWidth,
            float: 'left'
        });
        inc = Math.ceil(elementCount / perRow);
        for (j = inc * i; j < inc * (i + 1); j++) {
            $boxes.eq(j).appendTo($thisColumn);
        }
    }
}).resize(); //trigger resize function immediately

這篇關(guān)于如何使 CakePHP 的 HABTM 復(fù)選框按字母順序排列在列中的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Session is lost after an OAuth redirect(OAuth 重定向后會話丟失)
Pagination Sort in Cakephp 3.x(Cakephp 3.x 中的分頁排序)
CakePHP Shared core for multiple apps(CakePHP 多個(gè)應(yīng)用程序的共享核心)
Login [ Auth-gt;identify() ] always false on CakePHP 3(在 CakePHP 3 上登錄 [ Auth-identify() ] 始終為 false)
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)(致命錯(cuò)誤:允許的內(nèi)存大小為 134217728 字節(jié)已用盡(嘗試分配 87 字節(jié)))
主站蜘蛛池模板: 日本精品视频一区二区 | 国产精品国产成人国产三级 | 国产综合久久 | 亚洲欧美日韩精品久久亚洲区 | www.久久| 欧美黑人一区二区三区 | 毛片a级 | 亚洲不卡在线观看 | 老司机免费视频 | 国产精品视频一区二区三区 | 国产精品亚洲一区二区三区在线 | 中文字幕韩在线第一页 | 天天躁人人躁人人躁狂躁 | 国产一级淫片a直接免费看 免费a网站 | 爱综合 | 午夜影院在线观看视频 | 日韩一区二 | 亚洲天堂一区二区 | 好婷婷网| 精品1区2区 | 黄色亚洲网站 | 久久精品亚洲精品国产欧美 | 午夜成人免费视频 | 不卡一区二区三区四区 | 国产精品久久久久久久岛一牛影视 | 国产日韩一区二区三区 | 男女av| 国产精品一区二区在线 | 91福利在线观看视频 | 国产丝袜一区二区三区免费视频 | 国产分类视频 | 国产一二三区电影 | 亚洲va在线va天堂va狼色在线 | 欧美一级在线 | 亚洲 欧美 日韩 精品 | 亚洲永久入口 | 色爱综合网 | 久久99精品久久久久久 | 欧洲av一区 | www.久久久久久久久久久 | 久久69精品久久久久久久电影好 |