我有一个 React 复选框组件。我试图在每次单击时更改状态并根据之前的状态运行一个函数。在 React 上,每次单击按钮时,我都会尝试将事件返回到 index.js 中的 console.log 函数。
但它总是返回合成事件,我无法达到 event.target.value。
我的 index.js 和 props 是;
ReactDOM.render(<ReactCheckBox
isChecked={false}
textCheck="Checked"
textUncheck="Checked"
onCheckedRun={event => console.log(event.target)}
onUncheckedRun={event => console.log(event.target)}
buttonPosition="right"
/>, document.getElementById('myCheckBox'))
Run Code Online (Sandbox Code Playgroud)
我的 ReactCheckBox 组件是;
import React, { Component } from 'react'
class ReactCheckBox extends Component {
constructor(props) {
super(props)
this.state = {
checked: ""
}
this.onChangeHandler = this.onChangeHandler.bind(this)
}
componentDidMount() {
this.setState({
checked: this.props.isChecked
})
}
onChangeHandler(event) {
this.setState(function (previousState, props) {
console.log('State: ',this.state.checked)
if (previousState.checked === true) {
props.onCheckedRun(event)
} else …
Run Code Online (Sandbox Code Playgroud) 我开始将其作为学习 D3 的业余项目。所以请对我宽容一些;
目标: 制作交互式机场地图。当鼠标悬停在一个城市上时,飞机将从该城市的机场起飞并降落到目的地。
我遵循的步骤;
问题:当我有不止一架飞机要从一个城市起飞时,它就是不动。相反,它会保持在同一位置,直到转换结束。我无法向对象添加并发转换。
我的转换函数是这样的;
function myTransition(destPoi, originPoi) {
var tr_bl = true;
pathData = []; t_dest_poi = [];
if (tr_bl) {
//Origin destination coordinates taken from the Origin Poi
originPoint[0] = originPoi[1];
originPoint[1] = originPoi[2];
originPoint = geoMercator(originPoint);//Need transformation before using on screen.
var lineGenerator = d3.line().curve(d3.curveCatmullRom);
// Destination coordinate pairs transformed to screen coordinates
// and assigned to an array
for (i = 0; i < destPoi.length; …
Run Code Online (Sandbox Code Playgroud)