在反应本机组件中访问prors值的方式是什么
what is the way to access value of prors in react native Component
我想访问 get props of a clicked Component 以在我按下组件时获取 Marker 组件中名称为 number 的 prop 的值
我已经使用数组将我的组件推入
markers = []
this.markers.push(<Marker
onPress={()=> this._shapeFocused(event) }
coordinate={latLng} data={this.state.markerNumber}
key={"MN-" + this.state.markerNumber}
number={"5"}
//value={"marker"}
></Marker>)
推送组件后。按其中一个我想得到它的属性 "number" 的值以将它发送到全局存储 我试过 event.props.prop 但它不起作用
_shapeFocused(e) {
//get the key of the component
let key = e.target.number;
// send the component key to the global state:
let action = { type: "ShapeFocused", value: key}
this.props.dispatch(action)
}
如果你能告诉我如何在 React Native 中访问道具的价值,我会非常感激。
谢谢:)
event
是一个 React 合成事件,它对您的标记或其道具一无所知。在这种情况下,您似乎对事件细节并不真正感兴趣,只在触发时才感兴趣。
您可能想要的只是使用当前标记的值分派操作。
<Marker
onPress={() => shapeFocused(this.state.markerNumber)}
coordinate={latLng}
data={this.state.markerNumber}
key={"MN-" + this.state.markerNumber}
/>
function shapeFocused(markerNumber) {
const action = { type: "ShapeFocused", value: markerNumber }
this.props.dispatch(action)
}
我想访问 get props of a clicked Component 以在我按下组件时获取 Marker 组件中名称为 number 的 prop 的值
我已经使用数组将我的组件推入
markers = []
this.markers.push(<Marker
onPress={()=> this._shapeFocused(event) }
coordinate={latLng} data={this.state.markerNumber}
key={"MN-" + this.state.markerNumber}
number={"5"}
//value={"marker"}
></Marker>)
推送组件后。按其中一个我想得到它的属性 "number" 的值以将它发送到全局存储 我试过 event.props.prop 但它不起作用
_shapeFocused(e) {
//get the key of the component
let key = e.target.number;
// send the component key to the global state:
let action = { type: "ShapeFocused", value: key}
this.props.dispatch(action)
}
如果你能告诉我如何在 React Native 中访问道具的价值,我会非常感激。 谢谢:)
event
是一个 React 合成事件,它对您的标记或其道具一无所知。在这种情况下,您似乎对事件细节并不真正感兴趣,只在触发时才感兴趣。
您可能想要的只是使用当前标记的值分派操作。
<Marker
onPress={() => shapeFocused(this.state.markerNumber)}
coordinate={latLng}
data={this.state.markerNumber}
key={"MN-" + this.state.markerNumber}
/>
function shapeFocused(markerNumber) {
const action = { type: "ShapeFocused", value: markerNumber }
this.props.dispatch(action)
}