账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    请问各位大大,怎么将子组件里面的构造函数里面的回调给对外暴露。
    42
    0
    clusterize() {
          return new Clusterize({
            rows: this.DomArray,
            scrollId: this.scrollId,
            contentId: this.contentId,
            rows_in_block: this.rows_in_block,
            blocks_in_cluster: this.blocks_in_cluster,
            show_no_data_row: this.show_no_data_row,
            no_data_text: this.no_data_text,
            no_data_class: this.no_data_class,
            keep_parity: this.keep_parity,
            tag: this.tag,
    
            callbacks : {
              // 在用新的集群替换以前的集群之前会被调用。
              clusterWillChange: function() {},
              // 在用新的集群替换之前的集群后会被调用
              clusterChanged: function() {},
              // 将被调用滚动。返回进度状态
              scrollingProgress: function(progress) {}
            }
          });
        }
    

    怎么将callbacks给暴露呢。

    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 11 元积分
        全部回答
    • 0
    • 忽然之间 普通会员 1楼

      在React中,你可以通过设置state或者使用生命周期方法来对外暴露子组件的构造函数中的回调。

      1. 设置state:在子组件中,你可以通过访问到state来暴露回调。例如:

      ```jsx class MyComponent extends React.Component { constructor(props) { super(props); this.state = { callback: () => { console.log('Callback executed!'); }, }; }

      render() { return ( ); } } ```

      在这个例子中,我们设置了一个名为callback的state,它的值是一个函数。当用户点击按钮时,这个函数会被调用。

      1. 使用生命周期方法:React提供了许多生命周期方法,你可以使用这些方法来控制组件的生命周期,包括渲染,更新,删除等。在子组件的生命周期方法中,你可以调用回调。例如:

      ```jsx class MyComponent extends React.Component { constructor(props) { super(props); this.state = { callback: () => { console.log('Callback executed!'); }, }; }

      componentDidMount() { this.setState({ callback: () => { console.log('Callback executed!'); }, }); }

      componentWillUnmount() { this.setState({ callback: () => { console.log('Callback executed!'); }, }); }

      render() { return ( ); } } ```

      在这个例子中,我们在componentDidMountcomponentWillUnmountrender方法中都调用了callback

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部