javascript - Mixing react code with jQuery -
i have table checkbox on each row allow user select rows. in head of table have checkbox supposed toggle on/off or checkboxes in table.
to achieve i'm using jquery inside componentdidmount
method have strange feeling i'm doing things wrong...that react can this. since i'm @ start of react learning needed ask guys if can little more elegantly.
here's code:
class products extends component { componentdidmount() { const dispatch = this.props.dispatch; dispatch( asyncgetproducts() ); // not sure following part var self = this; $( '.proucts tbody tr' ).click( function() { $( ).find( '.checkbox' ).checkbox( "toggle" ); } ); $( '.proucts * .ui.checkbox' ).checkbox( { onchecked: function( el ) { if( $( ).attr( 'name' ) == "toggle_select_all" ) { $( '.proucts * .ui.checkbox' ).checkbox( "set checked" ); } }, onunchecked: function() { if( $( ).attr( 'name' ) == "toggle_select_all" ) { $( '.proucts * .ui.checkbox' ).checkbox( "set unchecked" ); } } } ); } // ...rest of code }
i feel doing wrong. instead of using jquery find elements, should use power of react. if have list of products go through each model object , have boolean
set true should render checked box. faster using jquery.
Comments
Post a Comment