Created
November 16, 2011 12:49
-
-
Save violetyk/1370003 to your computer and use it in GitHub Desktop.
[cakephp]treeviewを作るサンプル3/3(ビュー)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="clearfix"> | |
<label for="">階層から選ぶ</label> | |
<div class="input"> | |
<div id="sidetreecontrol"> <a href="?#">全て閉じる</a> | <a href="?#">全て開く</a> </div> | |
<ul id="category_tree" class="treeview"> | |
<?php | |
function expand($tree) { | |
$html = ''; | |
foreach($tree as $id => $name) { | |
if(is_array($name)) { | |
$html .= sprintf('<li><span>%s</span> <button type="button" class="btn small select_category" value="%s">追加</button><ul>%s</ul></li>', $name[0], $id, expand($name[1]) ); | |
} else { | |
$html .= sprintf('<li><span>%s</span> <button type="button" class="btn small select_category" value="%s">追加</button></li>', $name, $id); | |
} | |
} | |
return $html; | |
} | |
echo expand($category_tree); | |
?> | |
</ul> | |
</div> | |
</div> | |
<?php echo $html->scriptStart(array('inline' => true, 'safe' => true)); ?> | |
$(function(){ | |
// ツリービュー | |
$("#category_tree").treeview({ | |
// animated: "fast", // fast or medium or slow | |
collapsed: true, // 一番最初に全て閉じておく場合はtrue | |
//persist: "location", //locationの場合、a.href="?1.2.0"のURLパラメータでもらったらそこをひらいておく。 | |
//persist: "cookie", //cookieの場合、開いた場所をCookieに保存しておく。要jquery.cookie.js | |
// cookieId : "navigationtree", persist: "cookie"の場合のCookie名。デフォルトはtreeview | |
unique: false, // 他のツリーを開いたら閉じる場合はtrue | |
prerendered: false, | |
control: "#sidetreecontrol", | |
// toggle: function() { // コールバック | |
// console.log("%o was toggled", this); | |
// } | |
}); | |
}); | |
<?php echo $html->scriptEnd(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment