xloadtree demo

7975 단어
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="js/jquery-1.7.1.js"></script>
<!-- The xtree script file -->
<script src="xtree2.js"></script>
<script src="xloadtree2.js"></script>
<!-- Modify this file to change the way the tree looks -->
<link type="text/css" rel="stylesheet" href="xtree2.links.css">
<script type="text/javascript">

	var tree = new WebFXLoadTree("default", "tree.xml");
	//var tree = new WebFXTree('aaa');
	$(document).ready(function(){
		/* Change the behavior of the tree */
		tree.setBehavior('explorer');
		$('#deviceCategory').html(tree.toHtml());
		//document.write(tree);
	});

	function addNode() {
		var value = trim($('#insertedGroup').val());
		if(value == null || value == ""){
			alert(" ");
			return;
		}
		if(!tree.getSelected()){
			alert(" ");
			return;
		}
		if (tree.getSelected()) {
			tree.getSelected().add(new WebFXTreeItem(value));
		}
	}
	function delNode() {
		if(!tree.getSelected()){
			alert(" , ");
			return;
		}
		if (tree.getSelected()) {
			tree.getSelected().remove();
		}
	}
	function trim(string){
		return string.replace(/(^\s*)|(\s*$)/g, "");
	}
</script>
	
</head>
<body>
	<div style="float: left;">
		group
		<div id="deviceCategory">
		</div>
	
		<input type="text" id="insertedGroup" /><br>
		<input type="button" onclick="addNode();" value="add" />
		<input type="button" onclick="delNode();" value="del" /><br>
		<input type="button" value="expandAll" onclick="tree.expandAll();">
		<input type="button" value="collaspseAll" onclick="tree.collapseAll();"><br>
	</div>
	<div style="float: left;">
		list
	</div>
	
	
	<div id="alertBox" style="display: none;">
		<div style="margin: 20px;">group name:<label class="smallInput"><input id="tempalteName" class="inputS validate[required,maxSize[20]]" type="text" size="28" name="tempalteName"></label></div>
		<div style="margin: 20px;">father groupt name:<label class="textareaDiv"><textarea id="tempalteRemark" class="textarea validate[required,maxSize[30]]" rows="5" cols="80" name="remark"></textarea><br></label></div>
				
		<div style="position: relative;left:30px;cursor: pointer;">
			<span id="addSave">save</span>
		</div>
	</div>
</body>
</html>

xtree
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="js/jquery-1.7.1.js"></script>
<!-- The xtree script file -->
<script src="xtree.js"></script>
<script src="xloadtree.js"></script>
<script src="xmlextras.js"></script>
<!-- Modify this file to change the way the tree looks -->
<link type="text/css" rel="stylesheet" href="xtree.css">
<script type="text/javascript">

	var tree = new WebFXLoadTree("default", "tree.xml");
	//tree.write();
	//var tree = new WebFXTree('aaa');
	$(document).ready(function(){
		/* Change the behavior of the tree */
		tree.setBehavior('explorer');
		
		$('#deviceCategory').html(tree.toString());
		//document.write(tree);
	});

	function addNode() {
		var value = trim($('#insertedGroup').val());
		if(value == null || value == ""){
			alert(" ");
			return;
		}
		if(!tree.getSelected()){
			alert(" ");
			return;
		}
		if (tree.getSelected()) {
			tree.getSelected().add(new WebFXTreeItem(value));
		}
	}
	function delNode() {
		if(!tree.getSelected()){
			alert(" , ");
			return;
		}
		if (tree.getSelected()) {
			tree.getSelected().remove();
		}
	}
	function trim(string){
		return string.replace(/(^\s*)|(\s*$)/g, "");
	}
</script>
	
</head>
<body>
	<div style="float: left;">
		group
		<div id="deviceCategory">
		</div>
	
		<input type="text" id="insertedGroup" /><br>
		<input type="button" onclick="addNode();" value="add" />
		<input type="button" onclick="delNode();" value="del" /><br>
		<input type="button" value="expandAll" onclick="tree.expandAll();">
		<input type="button" value="collaspseAll" onclick="tree.collapseAll();"><br>
	</div>
	<div style="float: left;">
		list
	</div>
	
	
	<div id="alertBox" style="display: none;">
		<div style="margin: 20px;">group name:<label class="smallInput"><input id="tempalteName" class="inputS validate[required,maxSize[20]]" type="text" size="28" name="tempalteName"></label></div>
		<div style="margin: 20px;">father groupt name:<label class="textareaDiv"><textarea id="tempalteRemark" class="textarea validate[required,maxSize[30]]" rows="5" cols="80" name="remark"></textarea><br></label></div>
				
		<div style="position: relative;left:30px;cursor: pointer;">
			<span id="addSave">save</span>
		</div>
	</div>
</body>
</html>

tree.xml
<?xml version="1.0"?>

<tree>
	<tree text="Load "tree1.xml" (Should raise error)" src="tree1.xml" toolTip="Tool Tip"/>
	<tree text="Load "tree2.xml" (Should raise error)" src="tree2.xml"
		  onerror="this.setText('Load "tree2.xml" (Raised error)')"/>
	<tree text="Loaded Item 1" action="http://webfx.eae.net" />
	<tree text="Loaded Item 2" expanded="true">
		<tree text="Loaded Item 2.1" expanded="true">
			<tree text="Loaded Item 2.1.1" action="javascript:alert( tree.getSelected().getId() )" id="custom-id" />
		</tree>
	</tree>
	<tree text="Loaded Item 3 (click to set src)" onaction="this.setSrc(this.getSrc() ? null : 'tree3.xml')"
		  onload="this.setText('Loaded Item 3 (changed onload)')"/>
	<tree text="Load treeLARGE.xml" src="treeLARGE.xml" toolTip="XML file with 500 items"/>
	<tree text="Deep nesting" src="nest.xml.pl" />
</tree>

좋은 웹페이지 즐겨찾기