<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>checkbox tree</title>
<link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" />
<script type="text/javascript" src="../../adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../../ext-all.js"></script>
<script type="text/javascript">
Ext.onReady(function() {
Ext.QuickTips.init();
Ext.BLANK_IMAGE_URL = "extjs/resources/images/default/s.gif";
var mytree = new Ext.tree.TreePanel({
el : "container",
animate : true,
title : "Extjs",
collapsible : true,
enableDD : true,
enableDrag : true,
rootVisible : true,
autoScroll : true,
autoHeight : true,
width : 150,
lines : true
});
// 根节点
var root = new Ext.tree.TreeNode({
id : "root",
text : "root",
checked : false
});
for (var j = 1; j < 4; ++j) {
var node = root.appendChild(new Ext.tree.TreeNode({
text : 'company_A' + j,
allowDrag : false,
checked : false
}));
for (var n = 1; n < 4; ++n) {
node.appendChild(new Ext.tree.TreeNode({
text : 'items' + n,
allowDrag : false,
checked : false
}));
}
}
mytree.setRootNode(root);
mytree.render();
mytree.on('checkchange', function(node, checked) {
node.expand();
node.attributes.checked = checked;
node.eachChild(function(child) {
child.ui.toggleCheck(checked);
child.attributes.checked = checked;
child.fireEvent('checkchange', child,
checked);
});
}, mytree);
var button = new Ext.Button({
text : "checked_id",
handler : function() {
var b = mytree.getChecked();
var checkid = new Array;
for (var i = 0; i < b.length; i++) {
checkid.push(b[i].text);
}
alert(checkid.toString());
}
}).render(document.body, "btn");
});
</script>
</head>
<body>
<h1>Tree</h1>
<div id="container" style="overflow:auto; height:300px;width:250px;border:1px solid
#c3daf9;"></div>
</body>
</html>