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

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>

 

转载于:https://www.cnblogs.com/cengjingdeshuige/p/11276641.html

你可能感兴趣的:(得到后台数据,按照名称,循环赋值给表单)