나는 React와 Raphael을 모두 사용하여 프로젝트를 만들고 있는데, 어떻게 든 해결할 수없는 상황에 직면 해있다.React - 문맥 문제 - raphael-react
import React from 'react';
import {Raphael,Paper,Set,Circle,Ellipse,Image,Rect,Text,Path,Line} from 'react-raphael';
export default class PlanCdf extends React.Component {
\t onmouseover(){
\t \t console.log(this);
\t \t console.log(this.props.project);
\t }
\t drawTasks() {
\t \t return this.props.tasks.map((task) => {
\t \t \t return <Path mouseover={this.onmouseover} key={task._id} d={coords} attr={{"fill":"#444444", "stroke-width" : "2"}} />
\t \t })
\t }
\t render() {
\t \t return(
\t \t \t <Paper className={"paper"} width={this.state.paperWidth} height={this.state.paperHeight}>
\t \t \t \t <Set>
\t \t \t \t \t { this.drawTasks() }
\t \t \t \t </Set>
\t \t \t </Paper>
\t \t)
\t }
}
: 상태와 소품에 액세스하기 위해 일반적인 상황과
는 코드의간체 버전은 다음과 같다 onmouseover 동안 경로의 attr을 변경하려면 Path 컨텍스트가 있지만 어쨌든 나는 항상 둘 중 하나만 가져올 수 있습니다.
위의 예와 같이 경로에서이 컨텍스트 중 하나를 얻지 만 this.state에 액세스 할 수 없습니다. 또는 바인딩하면 더 이상 내 경로에 액세스하지 못했습니다. .
내가하지 않지만 해결책을 찾기 위해 관리 할 수 없습니다 아마 간단한 바인딩 문제
--- 편집 --- 내가 지금 어디에 서의
:
import React from 'react';
import {Raphael,Paper,Set,Circle,Ellipse,Image,Rect,Text,Path,Line} from 'react-raphael';
export default class PlanCdf extends React.Component {
constructor(props) {
super(props);
this.drawTasks = this.drawTasks.bind(this);
}
onmouseover(){
console.log(this.state);
}
drawTasks() {
return this.props.tasks.map((task) => {
return <PathWrapper mouseover={this.onmouseover} key={task._id} d={coords} attr={{"fill":"#444444", "stroke-width" : "3"}} />
})
}
render() {
return(
<Paper className={"paper"} width={this.state.paperWidth} height={this.state.paperHeight}>
<Set>
{ this.drawTasks() }
</Set>
</Paper>
)
}
}
export class PathWrapper extends React.Component {
constructor(props){
super(props);
}
onmouseover() {
console.log(this)
this.attr({'stroke-width':'5'})
this.props.mouseover()
}
render() {
return <Path mouseover={this.onmouseover} d={this.props.d} attr={this.props.attr} />
}
}
제안 된대로 새로운 PathWrapper 구성 요소에서 attr을 변경할 수 있습니다. 하지만 여전히 아무데도 내가 그 상태에 접근 할 수 있습니다. 부모 함수에 액세스하기 위해 소품으로 전송 된 함수를 호출하려고 시도했지만 속성을 변경하기 위해 Path 컨텍스트에 있어야하므로 할 수 없습니다 ... 하위 구성 요소로 pb를 다소 이동 시켰습니다
나는 우리가 올바른 방향으로 가고 있다고 느낍니다. 그러나 그것은 작동하지 않습니다. 그에 따라 질문을 편집 중입니다. – Ivo