日期:2014-05-16 浏览次数:20356 次
树的使用是很频繁的,对树节点的各种操作。和数据库的互动操作。
tree.html:
<!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"> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <title>树的展示</title> <!-- Ext --> <link rel="stylesheet" type="text/css" href="ext4/resources/css/ext-all.css" /> <script type="text/javascript" src="ext4/bootstrap.js"> </script> <script type="text/javascript" src="ext4/locale/ext-lang-zh_CN.js"> </script> <!-- tree.jsp page --> <link rel="stylesheet" type="text/css" href="ext4/ux/css/TabScrollerMenu.css" /> <script type="text/javascript" src="forever.js"> </script> <script type="text/javascript" src="tree-simple.js"> </script> <script type="text/javascript" src="tree-check.js"> </script> <script type="text/javascript" src="tree-app.js"> </script> </head> <body> </body> </html>
?forever.js是工具类:
Ext.ns("org.forever.util"); Ext.define('org.forever.util.TreeUtil', { extend: 'Object', userName: '默认值',//属性 constructor: function(config){//构造函数 Ext.apply(this, config); } }); //递归更新节点的选中状态 org.forever.util.TreeUtil.updateCheckStatus = function(parentNode, checked){ Ext.each(parentNode.childNodes, function(childNode, index, allItems){ //Ext.Msg.alert('节点信息',node.get('text')+';index=' + index); childNode.set('checked', checked); org.forever.util.TreeUtil.updateCheckStatus(childNode, checked); }); }
?tree-app.js是程序的初始化代码:
Ext.Loader.setConfig({ enabled: true }); Ext.Loader.setPath('Ext.ux', 'ext4/ux/'); Ext.onReady(function(){ var tabscrollermenu = Ext.create('Ext.ux.TabScrollerMenu', { ptype: 'tabscrollermenu', maxText: 15, pageSize: 10 }); var simpleTreePanel = createSimpleTree(); var checkTreePanel = createCheckTree(); var tabPanel = Ext.create('Ext.tab.Panel', { region: 'center', activeTab: 1, plugins: [tabscrollermenu], items: [simpleTreePanel, checkTreePanel] }); Ext.create('Ext.Window', { title: 'tree app', width: 500, height: 400, x: 100, y: 100, bodyStyle: 'padding: 5px;', layout: 'border', items: [tabPanel] }).show(); });
?tree-simple.js是创建一个简单的树,对节点提取值进行操作。
function createSimpleTree(){ var treeStore; var treePanel; var toolbarPanel; store = Ext.create('Ext.data.TreeStore', { root: { expanded: true, text: "根节点", children: [{ text: "1-1", leaf: true }, { text: "1-2", expanded: true, children: [{ text: "2-1", leaf: true }, { text: "2-2", leaf: true }] }, { text: "1-3", leaf: true }] } }); //工具条面板 toolbarPanel = new Ext.panel.Panel({ dockedItems: [{ xtype: 'toolbar', items: [{ text: '选中节点值', handler: function(){ var selectionMode = treePanel.getSelectionModel(); var modeType = selectionMode.getSelectionMode();//SINGLE