我有一个在React和Redux中使用服务器端呈现的应用程序。React/Redux - 在服务器端呈现页面后滚动div
在应用程序中有一个包含在div
标记内的信息网格。我附加了一个'ref'
属性,以便操作该特定的滚动条div
。
render(){
this.gridPosition()
return (
<div className='m_wrap' ref="scrollbars">
<TimeBar/>
<ChannelInfo info={this.props} />
</div>
)
}
而且gridPosition是:
gridPosition(){
if (this.props.slidePos == "Morning"){
this.refs.scrollbars.scrollLeft = 0;
} else if (this.props.slidePos == "Afternoon") {
this.refs.scrollbars.scrollLeft = 2880;
} else if (this.props.slidePos == "Evening") {
this.refs.scrollbars.scrollLeft = 5280;
} else if (this.props.slidePos == "Night") {
this.refs.scrollbars.scrollLeft = 7200;
}
}
所以滚动条的位置由this.props.slidePos
这个工程的应用程序加载时,但它不会将在正确的位置确定初始渲染。
我试过在componentDidMount()
函数中触发一个动作,但div
标记在服务器渲染后似乎没有连接到应用程序。
如果任何人都可以指出这一点或指出我正确的方向来解决它,我将非常感激。