EasyuiTree has been used in recent projects. I want to select the checkbox event, but the api only provides one onClick event. After Baidu and google, I 'd like to read JavaScript.
View the html generated by firebug and find that the checkobx is fake. It is just a span, and it changes the style back and forth.
The Code is as follows:
$ (". Tree-checkbox", tree). unbind (". tree"). bind ("click. tree", function (){
If ($ (this). hasClass ("tree-checkbox0 ")){
$ (This). removeClass ("tree-checkbox0"). addClass ("tree-checkbox1 ");
} Else {
If ($ (this). hasClass ("tree-checkbox1 ")){
$ (This). removeClass ("tree-checkbox1"). addClass ("tree-checkbox0 ");
} Else {
If ($ (this). hasClass ("tree-checkbox2 ")){
$ (This). removeClass ("tree-checkbox2"). addClass ("tree-checkbox1 ");
}
}
}
_ 2eb ($ (this). parent ());
_ 2ec ($ (this). parent ());
Return false;
});
Then let's look at its onClick event script.
Code
The Code is as follows:
$ (". Tree-node", tree)
....
Bind ("click. tree", function (){
$ (". Tree-node-selected", tree). removeClass ("tree-node-selected ");
$ (This). addClass ("tree-node-selected ");
If (opts. onClick ){
Var _ 2ea = this;
Var data = $. data (this, "tree-node ");
Opts. onClick. call (this, {id: data. id, text: data. text, attributes: data. attributes, target: _ 2ea });
}
})
Modify the check script accordingly.
The Code is as follows:
$ (". Tree-checkbox", tree). unbind (". tree"). bind ("click. tree", function (){
If ($ (this). hasClass ("tree-checkbox0 ")){
$ (This). removeClass ("tree-checkbox0"). addClass ("tree-checkbox1 ");
} Else {
If ($ (this). hasClass ("tree-checkbox1 ")){
$ (This). removeClass ("tree-checkbox1"). addClass ("tree-checkbox0 ");
} Else {
If ($ (this). hasClass ("tree-checkbox2 ")){
$ (This). removeClass ("tree-checkbox2"). addClass ("tree-checkbox1 ");
}
}
}
_ 2eb ($ (this). parent ());
_ 2ec ($ (this). parent ());
Return false;
}). Bind ("click. tree", function () {// Add gzl
If ($ (this). hasClass ("tree-checkbox1") & opts. onCheck ){
Var _ 2e9 = this;
Var data = $. data (this, "tree-node ");
Opts. onCheck. call (this, {id: data. id, text: data. text, attributes: data. attributes, target: _ 2e9 });
}
});
However, we couldn't get the Data value, so we had to $ (this). parent (). click () at last. The click Event and check were changed to the selected one. We used one method for the two events.
I hope to release a new version, or which of the following experts will change the version. I can do it too much.