Javascript 反应本族语拖放位置足球训练
我有这样一件事,队形是这样宣布的: 4-4-2:Javascript 反应本族语拖放位置足球训练,javascript,reactjs,react-native,drag-and-drop,Javascript,Reactjs,React Native,Drag And Drop,我有这样一件事,队形是这样宣布的: 4-4-2: [ [{}]//1 [{},{},{},{}...],//4 [{},{},{},{}...],//4 [{},{}...]//2 ] 所以我做了两个嵌套循环,一个是从门到中场滚动行(主阵列中的阵列数),另一个是每行滚动每个球员(单个阵列行中的obj数)。 到目前为止,它工作正常,我重复这一点,主队和客队都工作正常 问题是我想应用拖放。 我想做的是,球员的位置最初来自指定的训练,然后能够移动场上的每一个球员,甚至在球场的对方部分 有没有关于我如
[
[{}]//1
[{},{},{},{}...],//4
[{},{},{},{}...],//4
[{},{}...]//2
]
所以我做了两个嵌套循环,一个是从门到中场滚动行(主阵列中的阵列数),另一个是每行滚动每个球员(单个阵列行中的obj数)。
到目前为止,它工作正常,我重复这一点,主队和客队都工作正常
问题是我想应用拖放。
我想做的是,球员的位置最初来自指定的训练,然后能够移动场上的每一个球员,甚至在球场的对方部分
有没有关于我如何做到这一点的建议
import React, { Component } from 'react';
import { Text, View, StyleSheet, Image, ImageBackground } from 'react-native';
export default class FootballField extends Component {
constructor(props) {
super(props);
this.state = {
home: props.home,
away: props.away,
};
}
render() {
return (
<View style={styles.container}>
<ImageBackground
source={require('./images/footballfield.png')}
style={{
width: null,
height: null,
flex: 1,
}}>
<View style={{ backgroundColor: 'rgba(52, 52, 52, 0.45)', flex: 1 }}>
<View
style={{
flex: 1,
backgroundColor: 'rgba(204, 70, 43, 0)',
}}>
<View
style={{
flexDirection: 'row',
}}>
<Text
style={[
styles.text,
{
marginLeft: 20,
},
]}>
{this.state.home.module}
</Text>
<Text
style={[
styles.text,
{
position: 'absolute',
right: 20,
},
]}>
{this.state.home.name}
</Text>
</View>
{this.state.home.team.map((data, i) => (
<View style={styles.rowHome}>
{data.map((d, j) => (
<View style={styles.el}>
<View
style={{
flexDirection: 'row',
}}>
{this.state.home.home_team_events.map(
(el, z) =>
d.name == el.player &&
el.type_of_event == 'yellow-card' && (
<Image
source={require('./imagess/card-yellow.png')}
style={{
width: 12,
height: 15,
position: 'absolute',
left: -12,
}}
/>
)
)}
{this.state.home.home_team_events.map(
(el, z) =>
d.name == el.player &&
el.type_of_event == 'red-card' && (
<Image
source={require('./images/card-red.png')}
style={{
width: 12,
height: 15,
position: 'absolute',
left: -12,
}}
/>
)
)}
<View style={styles.playHome}>
<Text style={styles.text}>{d.number}</Text>
</View>
{this.state.home.home_team_events.map(
(el, z) =>
d.name == el.player &&
el.type_of_event == 'substitution-in' && (
<Image
source={require('./images/refresh.png')}
style={{
width: 12,
height: 12,
position: 'absolute',
right: -14,
}}
/>
)
)}
</View>
<Text style={styles.text}>{d.name}</Text>
</View>
))}
</View>
))}
</View>
<View
style={{
flex: 1,
backgroundColor: 'rgba(43, 99, 204, 0)',
paddingTop: 55,
}}>
{this.state.away.team.reverse().map((data, i) => (
<View style={styles.rowAway}>
{data.map((d, j) => (
<View style={styles.el}>
<Text style={styles.text}>{d.name}</Text>
<View
style={{
flexDirection: 'row',
}}>
{this.state.away.away_team_events.map(
(el, z) =>
d.name == el.player &&
el.type_of_event == 'yellow-card' && (
<Image
source={require('./images/card-yellow.png')}
style={{
width: 12,
height: 15,
position: 'absolute',
left: -12,
}}
/>
)
)}
{this.state.away.away_team_events.map(
(el, z) =>
d.name == el.player &&
el.type_of_event == 'red-card' && (
<Image
source={require('./images/card-red.png')}
style={{
width: 12,
height: 15,
position: 'absolute',
left: -12,
}}
/>
)
)}
<View style={styles.playAway}>
<Text style={styles.text}>{d.number}</Text>
</View>
{this.state.away.away_team_events.map(
(el, z) =>
d.name == el.player &&
el.type_of_event == 'substitution-in' && (
<Image
source={require('./images/refresh.png')}
style={{
width: 12,
height: 12,
position: 'absolute',
right: -14,
}}
/>
)
)}
</View>
</View>
))}
</View>
))}
<View
style={{
flexDirection: 'row',
}}>
<Text
style={[
styles.text,
{
marginLeft: 20,
},
]}>
{this.state.away.module}
</Text>
<Text
style={[
styles.text,
{
position: 'absolute',
right: 20,
},
]}>
{this.state.away.name}
</Text>
</View>
</View>
</View>
</ImageBackground>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
rowHome: {
flex: 1,
flexDirection: 'row',
},
rowAway: {
flex: 1,
flexDirection: 'row',
},
el: {
flexGrow: 1,
alignItems: 'center',
},
playHome: {
justifyContent: 'center',
width: 30,
height: 30,
borderRadius: 15,
borderWidth: 2,
borderColor: 'rgb(244, 67, 54)',
backgroundColor: 'rgba(244, 67, 54,0.5)',
},
playAway: {
justifyContent: 'center',
width: 30,
height: 30,
borderRadius: 15,
borderWidth: 2,
borderColor: 'rgb(3, 169, 244)',
backgroundColor: 'rgba(3, 169, 244,0.5)',
},
text: {
textAlign: 'center',
fontWeight: 'bold',
color: '#fff',
textShadowColor: 'rgba(0, 0, 0, 0.75)',
textShadowOffset: { width: 0, height: 1 },
textShadowRadius: 1,
fontSize: 15,
},
});
import React,{Component}来自'React';
从“react native”导入{文本、视图、样式表、图像、图像背景};
导出默认类足球场扩展组件{
建造师(道具){
超级(道具);
此.state={
家:道具,家,
客场:道具,客场,
};
}
render(){
返回(
{this.state.home.module}
{this.state.home.name}
{this.state.home.team.map((数据,i)=>(
{data.map((d,j)=>(
{this.state.home.home\u team\u events.map(
(el,z)=>
d、 name==el.player&&
el.type_of_事件=='黄牌'&&(
)
)}
{this.state.home.home\u team\u events.map(
(el,z)=>
d、 name==el.player&&
el.type_of_事件=='红牌'&&(
)
)}
{d.number}
{this.state.home.home\u team\u events.map(
(el,z)=>
d、 name==el.player&&
el.type_of_event=='substitution in'&&(
)
)}
{d.name}
))}
))}
{this.state.away.team.reverse().map((数据,i)=>(
{data.map((d,j)=>(
{d.name}
{this.state.away.away_team_events.map(
(el,z)=>
d、 name==el.player&&
el.type_of_事件=='黄牌'&&(
)
)}
{this.state.away.away_team_events.map(
(el,z)=>
d、 name==el.player&&
el.type_of_事件=='红牌'&&(
)
)}
{d.number}
{this.state.away.away_team_events.map(
(el,z)=>
d、 name==el.player&&
el.type_of_event=='substitution in'&&(
)
)}
))}
))}
{this.state.away.module}
{this.state.away.name}
);
}
}
const styles=StyleSheet.create({
容器:{
弹性:1,
},
rowHome:{
弹性:1,
flexDirection:'行',
},
罗维:{
弹性:1,
flexDirection:'行',
},
el:{
flexGrow:1,
对齐项目:“居中”,
},
游乐场:{
为内容辩护:“中心”,
宽度:30,
身高:30,
边界半径:15,
边界宽度:2,
边框颜色:“rgb(244,67,54)”,
背景颜色:“rgba(244,67,54,0.5)”,
},
季后赛:{
为内容辩护:“中心”,
宽度:30,
身高:30,
边界半径:15,
边界宽度:2,
边框颜色:“rgb(3169244)”,
背景颜色:“rgba(3169244,0.5)”,
},
正文:{
textAlign:'中心',
fontWeight:'粗体',
颜色:“#fff”,
textShadowColor:“rgba(0,0,0,0.75)”,
textShadowOffset:{宽度:0,高度:1},
文本阴影半径:1,
尺寸:15,
},
});