得到後臺數據,按照名稱,循環賦值給表單

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>接口獲取值後賦值</title>
</head>
<body>
    <script>
        let response = { // 後臺傳遞的json
            name: 'shui',
            age: 18,
            sex: 'boy'
        }
        let form = {} // 前端表單
        Object.keys(response).forEach(key => form[key] = response[key]) // 按照名稱一一賦值
        console.log(form)
    </script>
</body>
</html>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章