所以我的问题是我在mysql中有一个数据库,其中包含不同的自行车,这些数据库在我的数据库中存储在不同的位置,值FK_Location。
我想通过检查要移动的自行车,然后从下拉菜单中的两个位置(加利福尼亚和德克萨斯州)中进行选择来移动这些自行车,从而在FK_Locations之间移动这些自行车。
自行车1是位置1的自行车,自行车2是位置2的自行车。 唯一需要更改的是自行车的sql整数FK_Location。如果我手动更改sql中的值,则自行车会更改位置。复选框也可以使用;我只需要一个将数据发送到我的后端的按钮,a将FK_Location从例如1更改为2,但是我不确定如何编码。香港专业教育学院试图改变状态,但那只是局部的。
export default class Locations extends Component {
render() {
bikes1 = [];
bikes2 = [];
<p>1 - California</p>
<List>
{this.bikes1.map(bike1 => (
<List.Item key={bike1.BikeID}>
<input type="checkbox" checked={bike1.checked} onChange={e => (bike1.checked = e.target.checked)} />{' '}
{bike1.BikeID} - {bike1.Brand}
</List.Item>
))}
</List>
<p>2 - Texas</p>
<List>
{this.bikes2.map(bike2 => (
<List.Item key={bike2.BikeID}>
<input type="checkbox" checked={bike2.checked} onChange={e => (bike2.checked = e.target.checked)} />
{bike2.BikeID} - {bike2.Brand}
</List.Item>
))}
</List>
<select id="Location" value={this.FK_Location} onChange={e =>
(this.FK_Location = e.target.value)}>
<option value={1}>California</option>
<option value={2}>Texas</option>
</select>
mounted()
locationService.getBikesLocation(FK_Location => {
this.FK_Location = FK_Location;
});
locationService.getBikesLocation1(bikes1 => {
for (let bike of bikes1) bike.checked = false;
this.bikes1 = bikes1;
});
locationService.getBikesLocation2(bikes2 => {
for (let bike of bikes2) bike.checked = false;
this.bikes2 = bikes2;
});
class LocationService {
getBikesLocation(success) {
connection.query('select * from Bike', (error, results) => {
if (error) return console.error(error);
success(results);
});
}
getBikesLocation1(success) {
connection.query('select * from Bike where FK_Location = 1', (error, results) => {
if (error) return console.error(error);
success(results);
});
}
getBikesLocation2(success) {
connection.query('select * from Bike where FK_Location = 2', (error, results) => {
if (error) return console.error(error);
success(results);
});
}```
Could anyone try to make me any wiser here, or give an example?