使用动态密钥获取反应状态

时间:2017-09-02 17:37:37

标签: javascript reactjs

我已经知道如何使用动态密钥名称设置setState但是如何将值设置为具有动态密钥的状态?

示例

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "viverius_education";


$conn = new mysqli($servername, $username, $password, $dbname);

//$update_datum = $_POST['nov_datum'];
$update_status = $_POST['status'];
$update_st_odprtih_mest = $_POST['st_odprtih_mest'];
$update_ID = $_POST['ID'];


//if(!empty($_POST['nov_datum'])) { $update_datum = $_POST['nov_datum']; } else { $update_datum = NULL; }
if(!empty($_POST['status'])) { $update_status = $_POST['status']; } else { $update_status  = NULL; }
if(!empty($_POST['st_odprtih_mest'])) { $update_st_odprtih_mest = $_POST['st_odprtih_mest']; } else { $update_st_odprtih_mest = NULL; }
if(!empty($_POST['ID'])) { $update_ID = $_POST['ID']; } else { $update_ID = NULL; }



if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$sql = "UPDATE razpisani_tecaji 
SET 

STATUS = $update_status,
ST_ODPRTIH_MEST = $update_st_odprtih_mest
WHERE ID_TECAJA = $update_ID";

if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
header('Location: viv_settings.php'); exit;
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}$conn->close();

?>

1 个答案:

答案 0 :(得分:7)

我甚至没有想到将此视为第一,但我所做的只是

function thing(key) {
 let stuff = this.state[key];

 //Do stuff
}

它有效!