Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 混合react代码和jQuery_Javascript_Jquery_Reactjs - Fatal编程技术网

Javascript 混合react代码和jQuery

Javascript 混合react代码和jQuery,javascript,jquery,reactjs,Javascript,Jquery,Reactjs,我有一个表,每行都有一个复选框,允许用户选择行。在表格的顶部,我有一个复选框,用来打开/关闭表格中的复选框 为了实现这一点,我在componentDidMount方法中使用jquery,但我有一种奇怪的感觉,我做错了事情……反应本身可以做到这一点。因为我刚刚开始学习react,所以我想问你们,我能不能更优雅一点 这是我的密码: class Products extends Component { componentDidMount() { const dispat

我有一个表,每行都有一个复选框,允许用户选择行。在表格的顶部,我有一个复选框,用来打开/关闭表格中的复选框

为了实现这一点,我在
componentDidMount
方法中使用jquery,但我有一种奇怪的感觉,我做错了事情……反应本身可以做到这一点。因为我刚刚开始学习react,所以我想问你们,我能不能更优雅一点

这是我的密码:

class Products extends Component
{
    componentDidMount()
    {
        const dispatch = this.props.dispatch;
        dispatch( asyncGetProducts() );

        // NOT SURE ABOUT FOLLOWING PART
        var self = this;
        $( '.proucts tbody tr' ).click( function() {
            $( this ).find( '.checkbox' ).checkbox( "toggle" );
        } );

        $( '.proucts * .ui.checkbox' ).checkbox( {
            onChecked: function( el ) {
                if( $( this ).attr( 'name' ) == "toggle_select_all" ) {
                    $( '.proucts * .ui.checkbox' ).checkbox( "set checked" );
                }
            },
            onUnchecked: function() {
                if( $( this ).attr( 'name' ) == "toggle_select_all" ) {
                    $( '.proucts * .ui.checkbox' ).checkbox( "set unchecked" );
                }
            }
        } );
    }

    //  ...rest of code
}

我觉得你做错了。与使用jQuery查找所有元素不同,您应该使用React的强大功能。如果已经有所有产品的列表,则检查每个模型对象,并将
布尔值设置为true,该值应显示为复选框。这将比使用jQuery更快