Traverse Tree nodes
Function travel (treeid) {// The parameter is the ID of the tree. Do not add it #
VaR roots = $ ('#' + treeid). Tree ('getroots'), children, I, J;
For (I = 0; I <roots. length; I ++ ){
Alert (roots [I]. Text );
Childrenstm(('{'{treeid}.tree('getchildren', roots{ I }.tar get );
For (j = 0; j <children. length; j ++) Alert (Children [J]. Text );
}
}
$ (Function (){
$ ('# Tt2'). Tree ({
Checkbox: True,
URL: 'tree _ data. json ',
Onclick: function (node ){
$ (This). Tree ('toggle ', node.tar get );
// Alert ('You dbclick' + node. Text );
},
Oncontextmenu: function (E, node ){
E. preventdefault ();
$ ('# Tt2'). Tree ('select', node.tar get );
$ ('# Mm'). menu ('show ',{
Left: E. pagex,
Top: E. Pagey
});
}
});
});
Function reload (){
VaR node = $ ('# tt2'). Tree ('getselected ');
If (node ){
$ ('# Tt2'). Tree ('reload', node.tar get );
}
Else {
$ ('# Tt2'). Tree ('reload ');
}
}
Function getchildren (){
VaR node = $ ('# tt2'). Tree ('getselected ');
If (node ){
VaR children = $ ('# tt2'). Tree ('getchildren', node.tar get );
}
Else {
VaR children = $ ('# tt2'). Tree ('getchildren ');
}
VaR S = '';
For (VAR I = 0; I <children. length; I ++ ){
S + = children [I]. Text + ',';
}
Alert (s );
}
Function getchecked (){
VaR nodes = $ ('# tt2'). Tree ('getchecked ');
VaR S = '';
For (VAR I = 0; I <nodes. length; I ++ ){
If (s! = '')
S + = ',';
S + = nodes [I]. text;
}
Alert (s );
}
Function getselected (){
VaR node = $ ('# tt2'). Tree ('getselected ');
Alert (node. Text );
}
Function collapse (){
VaR node = $ ('# tt2'). Tree ('getselected ');
$ ('# Tt2'). Tree ('collapse', node.tar get );
}
Function expand (){
VaR node = $ ('# tt2'). Tree ('getselected ');
$ ('# Tt2'). Tree ('expand', node.tar get );
}
Function collapseall (){
VaR node = $ ('# tt2'). Tree ('getselected ');
If (node ){
$ ('# Tt2'). Tree ('collapseall', node.tar get );
}
Else {
$ ('# Tt2'). Tree ('collapseall ');
}
}
Function expandall (){
VaR node = $ ('# tt2'). Tree ('getselected ');
If (node ){
$ ('# Tt2'). Tree ('pandall', node.tar get );
}
Else {
$ ('# Tt2'). Tree ('pandall ');
}
}
Function append (){
VaR node = $ ('# tt2'). Tree ('getselected ');
$ ('# Tt2'). Tree ('append ',{
Parent: (node? Node.tar get: NULL ),
Data :[{
Text: 'new1 ',
Checked: True
},{
Text: 'new2 ',
State: 'closed ',
Children :[{
Text: 'subnew1'
},{
Text: 'subnew2'
}]
}]
});
}
Function remove (){
VaR node = $ ('# tt2'). Tree ('getselected ');
$ ('# Tt2'). Tree ('delete', node.tar get );
}
Function Update (){
VaR node = $ ('# tt2'). Tree ('getselected ');
If (node ){
Node. Text = '<span style = "font-weight: bold"> new text <\/span> ';
Node. iconcls = 'icon-save ';
$ ('# Tt2'). Tree ('update', node );
}
}
Function isleaf (){
VaR node = $ ('# tt2'). Tree ('getselected ');
VaR B = $ ('# tt2'). Tree ('isleaf', node.tar get );
Alert (B)
}
Function getnode (type ){
VaR node = $ ('# tt2'). Tree ('getchecked ');
VaR chilenodes = '';
VaR parantsnodes = '';
VaR prevnode = '';
For (VAR I = 0; I <node. length; I ++ ){
If ($ ('# tt2'). Tree ('isleaf', nodepolici2.16.tar get )){
Chilenodes + = node [I]. Text + ',';
VaR pnode = $ ('# tt2'). Tree ('getparent', nodepolici2.16.tar get );
If (prevnode! = Pnode. Text ){
Parantsnodes + = pnode. Text + ',';
Prevnode = pnode. text;
}
}
}
Chilenodes = chilenodes. substring (0, chilenodes. Length-1 );
Parantsnodes = parantsnodes. substring (0, parantsnodes. Length-1 );
If (type = 'child '){
Return chilenodes;
}
Else {
Return parantsnodes
};
};
Function getnodes (){
Alert (getnode ('fnode') + "," + getnode ('child '));
}
Function donode (){
VaR c = "";
VaR P = "";
$ (". Tree-checkbox1"). Parent (). Children ('. Tree-title'). Each (function (){
C + = $ (this). Parent (). ATTR ('node-id') + ",";
});
$ (". Tree-checkbox2"). Parent (). Children ('. Tree-title'). Each (function (){
P + = $ (this). Parent (). ATTR ('node-id') + ",";
});
VaR STR = (C + p );
STR = Str. substring (0, str. Length-1 );
Alert (STR );
}