jsp中帶有checkbox的屬性菜單需要用easyui組件來實(shí)現(xiàn),代碼如下:
為衡水等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計(jì)制作服務(wù),及衡水網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)、衡水網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!
!DOCTYPE html
html
head
meta charset="UTF-8"
titleCheckBox Tree - jQuery EasyUI Demo/title
link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"
link rel="stylesheet" type="text/css" href="../../themes/icon.css"
link rel="stylesheet" type="text/css" href="../demo.css"
script type="text/javascript" src="../../jquery.min.js"/script
script type="text/javascript" src="../../jquery.easyui.min.js"/script
/head
body
h2CheckBox Tree/h2
pTree nodes with check boxes./p
div style="margin:20px 0;"
a href="#" class="easyui-linkbutton" onclick="getChecked()"GetChecked/a
/div
div style="margin:10px 0"
input type="checkbox" checked onchange="$('#tt').tree({cascadeCheck:$(this).is(':checked')})"CascadeCheck
input type="checkbox" onchange="$('#tt').tree({onlyLeafCheck:$(this).is(':checked')})"OnlyLeafCheck
/div
div class="easyui-panel" style="padding:5px"
ul id="tt" class="easyui-tree" data-options="url:'tree_data1.json',method:'get',animate:true,checkbox:true"/ul
/div
script type="text/javascript"
function getChecked(){
var nodes = $('#tt').tree('getChecked');
var s = '';
for(var i=0; inodes.length; i++){
if (s != '') s += ',';
s += nodes[i].text;
}
alert(s);
}
/script
/body
/html
運(yùn)行效果:
呵呵,你可以看一下easyUI框架的功能。
如果非要自己寫的話:大體就是這樣的:
ul
li id="ts"圖書
ul id="tsts"li id="kx"科學(xué)類/lili id="wx"文學(xué)類/li/ul
/li
li id="yx"影像/li
/ul
其他的自己嵌套進(jìn)去就可以了;
然后主要是在js里的處理:
$(functoin(){
var tsts = 0;
$("#tx").click(functon(){
if(tsts==0){
//this.child.display=none;具體設(shè)置屬性的方法你看一下是不是這樣的。
$("#tsts").css("display":"none");
tsts = 1;
} else{
$("#tsts").css("display":"block");
tsts = 0;
}
});
});
好吧,結(jié)構(gòu)大體就是這樣的了。還有那個(gè)加減號的變化你自己看一下。也要綁定的單擊事件里面。
package?com.csii;
import?java.awt.GridLayout;
import?javax.swing.JEditorPane;
import?javax.swing.JFrame;
import?javax.swing.JPanel;
import?javax.swing.JScrollPane;
import?javax.swing.JTree;
import?javax.swing.SwingUtilities;
import?javax.swing.UIManager;
import?javax.swing.event.TreeSelectionEvent;
import?javax.swing.event.TreeSelectionListener;
import?javax.swing.tree.DefaultMutableTreeNode;
import?javax.swing.tree.TreeSelectionModel;
public?class?TreeDemo1?extends?JFrame?implements?TreeSelectionListener?{
private?static?final?long?serialVersionUID?=?1L;
private?JPanel?jContentPane?=?null;
private?JTree?jTree?=?null;
private?JEditorPane?jEditorPane?=?null;
private?JScrollPane?jScrollPane?=?null;
public?JScrollPane?getjScrollPane()?{
if(jScrollPane==null){
jScrollPane?=?new?JScrollPane();
jScrollPane.setViewportView(getJTree());
}
return?jScrollPane;
}
DefaultMutableTreeNode?top?=?null;?//?@jve:decl-index=0:
/**
?*?This?is?the?default?constructor
?*/
public?TreeDemo1()?{
super();
initialize();
}
/**
?*?This?method?initializes?this
?*
?*?@return?void
?*/
private?void?initialize()?{
this.setSize(438,?309);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
/**
?*?This?method?initializes?jContentPane
?*
?*?@return?javax.swing.JPanel
?*/
private?JPanel?getJContentPane()?{
if?(jContentPane?==?null)?{
GridLayout?gridLayout?=?new?GridLayout();
gridLayout.setRows(1);
gridLayout.setColumns(2);
jContentPane?=?new?JPanel();
jContentPane.setLayout(gridLayout);
jContentPane.add(getjScrollPane(),?null);
jContentPane.add(getJEditorPane(),?null);
}
return?jContentPane;
}
/**
?*?This?method?initializes?jTree
?*
?*?@return?javax.swing.JTree
?*/
private?JTree?getJTree()?{
if?(jTree?==?null)?{
top?=?new?DefaultMutableTreeNode("黃山");
createNodes(top);
jTree?=?new?JTree(top);
jTree.getSelectionModel().setSelectionMode(
TreeSelectionModel.SINGLE_TREE_SELECTION);
jTree.addTreeSelectionListener(this);
}
return?jTree;
}
private?void?createNodes(DefaultMutableTreeNode?top)?{
DefaultMutableTreeNode?jingdian?=?null,?jiaotong?=?null,?zhusu?=?null,?binguan?=?null,?luying?=?null,?jiesu?=?null;
jingdian?=?new?DefaultMutableTreeNode("景點(diǎn)");
jingdian.add(new?DefaultMutableTreeNode("景點(diǎn)1"));
jingdian.add(new?DefaultMutableTreeNode("景點(diǎn)2"));
jiaotong?=?new?DefaultMutableTreeNode("交通");
jiaotong.add(new?DefaultMutableTreeNode("路線1"));
jiaotong.add(new?DefaultMutableTreeNode("路線2"));
jiaotong.add(new?DefaultMutableTreeNode("路線3"));
zhusu?=?new?DefaultMutableTreeNode("住宿");
zhusu.add(new?DefaultMutableTreeNode("A住宿"));
zhusu.add(new?DefaultMutableTreeNode("B住宿"));
zhusu.add(new?DefaultMutableTreeNode("C住宿"));
binguan?=?new?DefaultMutableTreeNode("賓館");
binguan.add(new?DefaultMutableTreeNode("X賓館"));
binguan.add(new?DefaultMutableTreeNode("Y賓館"));
binguan.add(new?DefaultMutableTreeNode("Z賓館"));
binguan.add(new?DefaultMutableTreeNode("XYZ賓館"));
luying?=?new?DefaultMutableTreeNode("露營");
luying.add(new?DefaultMutableTreeNode("方式1"));
luying.add(new?DefaultMutableTreeNode("方式2"));
jiesu?=?new?DefaultMutableTreeNode("借宿");
jiesu.add(new?DefaultMutableTreeNode("借宿1"));
jiesu.add(new?DefaultMutableTreeNode("借宿2"));
jiesu.add(new?DefaultMutableTreeNode("借宿3"));
top.add(jingdian);
top.add(jiaotong);
top.add(zhusu);
top.add(binguan);
top.add(luying);
top.add(jiesu);
}
/**
?*?This?method?initializes?jEditorPane
?*
?*?@return?javax.swing.JEditorPane
?*/
private?JEditorPane?getJEditorPane()?{
if?(jEditorPane?==?null)?{
jEditorPane?=?new?JEditorPane();
}
return?jEditorPane;
}
@Override
public?void?valueChanged(TreeSelectionEvent?e)?{
DefaultMutableTreeNode?node?=?(DefaultMutableTreeNode)?jTree
.getLastSelectedPathComponent();
if?(node?==?null)
//?Nothing?is?selected.
return;
if(node.isRoot()){
jEditorPane.setText("黃山的簡介");
}
}
public?static?void?main(String[]?args)?{
SwingUtilities.invokeLater(new?Runnable()?{
@Override
public?void?run()?{
try?{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception?e){
e.printStackTrace();
}
new?TreeDemo1().setVisible(true);
}
});
}
}
是要返回一個(gè)json串吧。mybytis里設(shè)置好要返回自定義的結(jié)果集合。就直接可以
在圖形界面中添加文本框架實(shí)現(xiàn)文本編輯,通過鼠標(biāo)菜單欄添加事件監(jiān)聽實(shí)現(xiàn)保存。
在開發(fā)中我們經(jīng)常會遇到左邊是樹形菜單,右邊是一個(gè)顯示列表,單擊左邊的樹形菜單項(xiàng)時(shí),右邊會顯示該菜單里面相對應(yīng)的內(nèi)容。在實(shí)戰(zhàn)開發(fā)中經(jīng)常有需要處理樹形菜單、樹形目錄等等等業(yè)務(wù)需求。
而對于這種產(chǎn)品,在設(shè)計(jì)數(shù)據(jù)庫時(shí)也建議使用idparentId的結(jié)構(gòu)來做。
package tree;
import java.util.LinkedList;
import java.util.List;
/**
* 功能:把一個(gè)數(shù)組的值存入二叉樹中,然后進(jìn)行3種方式的遍歷
*
* 參考資料0:數(shù)據(jù)結(jié)構(gòu)(C語言版)嚴(yán)蔚敏
*
* 參考資料1:
*
* 參考資料2:
*
* @author ocaicai@yeah.net @date: 2011-5-17
*
*/
public class BinTreeTraverse2 {
private int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
private static ListNode nodeList = null;
/**
* 內(nèi)部類:節(jié)點(diǎn)
*
* @author ocaicai@yeah.net @date: 2011-5-17
*
*/
private static class Node {
Node leftChild;
Node rightChild;
int data;
Node(int newData) {
leftChild = null;
rightChild = null;
data = newData;
}
}
public void createBinTree() {
nodeList = new LinkedListNode();
// 將一個(gè)數(shù)組的值依次轉(zhuǎn)換為Node節(jié)點(diǎn)
for (int nodeIndex = 0; nodeIndex array.length; nodeIndex++) {
nodeList.add(new Node(array[nodeIndex]));
}
// 對前l(fā)astParentIndex-1個(gè)父節(jié)點(diǎn)按照父節(jié)點(diǎn)與孩子節(jié)點(diǎn)的數(shù)字關(guān)系建立二叉樹
for (int parentIndex = 0; parentIndex array.length / 2 - 1; parentIndex++) {
// 左孩子
nodeList.get(parentIndex).leftChild = nodeList
.get(parentIndex * 2 + 1);
// 右孩子
nodeList.get(parentIndex).rightChild = nodeList
.get(parentIndex * 2 + 2);
}
// 最后一個(gè)父節(jié)點(diǎn):因?yàn)樽詈笠粋€(gè)父節(jié)點(diǎn)可能沒有右孩子,所以單獨(dú)拿出來處理
int lastParentIndex = array.length / 2 - 1;
// 左孩子
nodeList.get(lastParentIndex).leftChild = nodeList
.get(lastParentIndex * 2 + 1);
// 右孩子,如果數(shù)組的長度為奇數(shù)才建立右孩子
if (array.length % 2 == 1) {
nodeList.get(lastParentIndex).rightChild = nodeList
.get(lastParentIndex * 2 + 2);
}
}
/**
* 先序遍歷
*
* 這三種不同的遍歷結(jié)構(gòu)都是一樣的,只是先后順序不一樣而已
*
* @param node
* 遍歷的節(jié)點(diǎn)
*/
public static void preOrderTraverse(Node node) {
if (node == null)
return;
System.out.print(node.data + " ");
preOrderTraverse(node.leftChild);
preOrderTraverse(node.rightChild);
}
/**
* 中序遍歷
*
* 這三種不同的遍歷結(jié)構(gòu)都是一樣的,只是先后順序不一樣而已
*
* @param node
* 遍歷的節(jié)點(diǎn)
*/
public static void inOrderTraverse(Node node) {
if (node == null)
return;
inOrderTraverse(node.leftChild);
System.out.print(node.data + " ");
inOrderTraverse(node.rightChild);
}
/**
* 后序遍歷
*
* 這三種不同的遍歷結(jié)構(gòu)都是一樣的,只是先后順序不一樣而已
*
* @param node
* 遍歷的節(jié)點(diǎn)
*/
public static void postOrderTraverse(Node node) {
if (node == null)
return;
postOrderTraverse(node.leftChild);
postOrderTraverse(node.rightChild);
System.out.print(node.data + " ");
}
public static void main(String[] args) {
BinTreeTraverse2 binTree = new BinTreeTraverse2();
binTree.createBinTree();
// nodeList中第0個(gè)索引處的值即為根節(jié)點(diǎn)
Node root = nodeList.get(0);
System.out.println("先序遍歷:");
preOrderTraverse(root);
System.out.println();
System.out.println("中序遍歷:");
inOrderTraverse(root);
System.out.println();
System.out.println("后序遍歷:");
postOrderTraverse(root);
}
}