extjs studies four treePanel
Theuseofthetreeisveryfrequent,thevariousoperationsonthetreenode.Anddatabaseinteractivity.
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> Tree display </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>
forever.jsaretools:
Ext.ns("org.forever.util"); Ext.define('org.forever.util.TreeUtil', { extend: 'Object', userName: ' Default ',//property constructor: function(config){// Constructor Ext.apply(this, config); } }); // Recursive update node selected org.forever.util.TreeUtil.updateCheckStatus = function(parentNode, checked){ Ext.each(parentNode.childNodes, function(childNode, index, allItems){ //Ext.Msg.alert(' Node information ',node.get('text')+';index=' + index); childNode.set('checked', checked); org.forever.util.TreeUtil.updateCheckStatus(childNode, checked); }); }
tree-app.jsistheprocessinitializationcode:
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.jsistocreateasimpletree,extractthevalueofthenodeoperation.
function createSimpleTree(){ var treeStore; var treePanel; var toolbarPanel; store = Ext.create('Ext.data.TreeStore', { root: { expanded: true, text: " The root node ", 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 }] } }); // Tool Panel toolbarPanel = new Ext.panel.Panel({ dockedItems: [{ xtype: 'toolbar', items: [{ text: ' Selected node value ', handler: function(){ var selectionMode = treePanel.getSelectionModel(); var modeType = selectionMode.getSelectionMode();//SINGLE, MULTI or SIMPLE var selection = selectionMode.getSelection();// Gets the selected values if (selection.length == 1) { Ext.MessageBox.show({ title: ' Node actions ', msg: " Value of the selected node :" + selection[0].data.text, icon: Ext.MessageBox.INFO }); } else { Ext.MessageBox.show({ title: ' Node actions ', msg: ' The node is not selected ', icon: Ext.MessageBox.INFO }); } } }] }] }); // Tree Panel treePanel = Ext.create('Ext.tree.Panel', { title: 'simple-tree', store: store, closable: true, rootVisible: true,// Display the root node dockedItems: [toolbarPanel], listeners: { itemclick: function(view, record, item, index, e){// In the select the event does not fire . Ext.MessageBox.show({ title: ' Node actions ', msg: 'itemclick:index=' + index + ",text=" + record.data.text, icon: Ext.MessageBox.INFO }); } } //renderTo: 'simple-tree-div'//<div></div> }); // Register event actions treePanel.getSelectionModel().on('select', function(selModel, record){ Ext.MessageBox.show({ title: ' Node actions ', msg: 'select:modeType=' + selModel.mode + ",text=" + record.data.text, icon: Ext.MessageBox.INFO }); }); return treePanel; }
tree-check.jsisatreewithacheckboxtoextractthevalueoftheselectedtree:
function createCheckTree(){ var treeStore; var treePanel; var toolbarPanel; store = Ext.create('Ext.data.TreeStore', { root: { checked: false, expanded: true, text: " The root node ", children: [{ checked: false, text: "1-1", leaf: true }, { checked: false, text: "1-2", expanded: true, children: [{ checked: false, text: "2-1", leaf: true }, { checked: false, text: "2-2", children: [{ checked: false, text: "2-2-1", leaf: true }, { checked: false, text: "2-2-2", leaf: true }] }] }, { checked: false, text: "1-3", leaf: true }] } }); toolbarPanel = new Ext.panel.Panel({ dockedItems: [{ xtype: 'toolbar', items: [{ text: ' Selected node value ', handler: function(target, e){ var records = treePanel.getView().getChecked(), names = []; Ext.Array.each(records, function(rec){ names.push(rec.get('text')); }); if (records.length > 0) { Ext.MessageBox.show({ title: 'Selected Nodes', msg: names.join('<br />'), icon: Ext.MessageBox.INFO }); } else { Ext.MessageBox.show({ title: ' Node actions ', msg: ' The node is not selected ', icon: Ext.MessageBox.INFO }); } } }] }] }); treePanel = Ext.create('Ext.tree.Panel', { title: 'check-tree', store: store, animate: true, closable: true, rootVisible: true, dockedItems: [toolbarPanel], listeners: { itemclick: function(view, record, item, index, e){ }, checkchange: function(node, checked){ org.forever.util.TreeUtil.updateCheckStatus(node, checked); } } }); return treePanel; }
相关推荐
InJavaWeTrust 2020-05-15
Chydar 2012-09-20
natejeams 2020-01-15
zcpHappy 2014-01-11
pythonclass 2019-11-07
JF0 2019-11-03
ElementW 2015-02-15
干货集合 2014-05-14
kaiya0 2012-06-13
cscscssjsp 2012-03-05
drinow 2019-07-12
coderMozart 2019-06-30
t0ckh 2012-11-11
中等偏下 2017-02-22
nicepainkiller 2016-07-26
云帆大数据 2016-01-11
longshengguoji 2015-09-07