Javascript 如何避免在使用Alt.js';什么是连接商店?
我使用Alt.js的connectToStores来访问组件内的存储状态,但是当我试图从另一个组件(使用ref)调用该组件的方法时,该方法似乎因为包装器组件(提供未定义的方法)而丢失 comp_a.jsJavascript 如何避免在使用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() {
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商店是个不错的选择,尽管还有其他的。很高兴你成功了!