Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.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 如何避免在使用Alt.js';什么是连接商店?_Javascript_Reactjs_Flux_Reactjs Flux_Alt.js - Fatal编程技术网

Javascript 如何避免在使用Alt.js';什么是连接商店?

Javascript 如何避免在使用Alt.js';什么是连接商店?,javascript,reactjs,flux,reactjs-flux,alt.js,Javascript,Reactjs,Flux,Reactjs Flux,Alt.js,我使用Alt.js的connectToStores来访问组件内的存储状态,但是当我试图从另一个组件(使用ref)调用该组件的方法时,该方法似乎因为包装器组件(提供未定义的方法)而丢失 comp_a.js class CompA extends React.Component { ... static getStores() { ... } static getPropsFromStores() { ... } ... method() {

我使用Alt.js的connectToStores来访问组件内的存储状态,但是当我试图从另一个组件(使用ref)调用该组件的方法时,该方法似乎因为包装器组件(提供未定义的方法)而丢失

comp_a.js

class CompA extends React.Component {

    ...

    static getStores() { ... }
    static getPropsFromStores() { ... }

    ...

    method() { 
    }

    ...
}

export default connectToStores(CompA);
class CompB extends React.Component {

    ...

    test() {
        // Causes error because "method()" is lost during connectToStores export
        // It seems that connectToStores doesn't inherit the base component, instead it wraps the component with another component.
        this.refs.other.method(); 
    }

    ...

    render() { 
        return (
            <CompA ref="other" />
        );
    }

    ...

}
comp_b.js

class CompA extends React.Component {

    ...

    static getStores() { ... }
    static getPropsFromStores() { ... }

    ...

    method() { 
    }

    ...
}

export default connectToStores(CompA);
class CompB extends React.Component {

    ...

    test() {
        // Causes error because "method()" is lost during connectToStores export
        // It seems that connectToStores doesn't inherit the base component, instead it wraps the component with another component.
        this.refs.other.method(); 
    }

    ...

    render() { 
        return (
            <CompA ref="other" />
        );
    }

    ...

}
class CompB扩展了React.Component{
...
测试(){
//由于在connectToStores导出过程中丢失了“method()”而导致错误
//connectToStores似乎没有继承基本组件,而是用另一个组件包装该组件。
this.refs.other.method();
}
...
render(){
返回(
);
}
...
}
  • 有没有办法仍然调用方法()

  • 有没有办法访问包装好的组件


  • @Josh Davidimiller我也想过,但这就是我如何在不创建一个全新的通量/商店的情况下让它工作的原因。它基本上有两个组件,一个是折叠/展开另一个的按钮。按下按钮时,另一个组件称为hide()/show()方法。我怎样才能使这项工作更好(将一个组件置于另一个组件内不是一个选项)@joshdavidimiller我将逻辑移到了flux。效果很好,比预期的要好。flux商店是个不错的选择,尽管还有其他的。很高兴你成功了@Josh Davidimiller我也想过,但这就是我如何在不创建一个全新的通量/商店的情况下让它工作的原因。它基本上有两个组件,一个是折叠/展开另一个的按钮。按下按钮时,另一个组件称为hide()/show()方法。我怎样才能使这项工作更好(将一个组件置于另一个组件内不是一个选项)@joshdavidimiller我将逻辑移到了flux。效果很好,比预期的要好。flux商店是个不错的选择,尽管还有其他的。很高兴你成功了!