得到后台数据,按照名称,循环赋值给表单

<!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>

 

posted @ 2019-07-31 15:31 曾经的水哥 阅读(...) 评论(...) 编辑 收藏