当前位置:网站首页>How to convert object data into arrays
How to convert object data into arrays
2022-07-25 09:34:00 【Fragrant grass setting sun_ dawn】
List of articles
Preface
Sometimes the data given by the back end of the project cannot fully meet the data requirements of the front end , such as element-ui+vue In the portfolio , The drop-down box data is in the form of an array . However, the back-end colleagues do give object data , Of course, you can negotiate with the backend to change the data you want … But this is often troublesome , The front end that likes to write code quietly decides to convert by itself .
Tips : Text content
One 、 Data from the back end

Two 、 How to convert
console.log('res:', res);
let resObj = res.data.data; // Get the object data given by the background
let arr = []; // Define an empty array
for (let key in resObj) {
// use for Cyclic conversion resObj object
arr.push({
value: key,
label: resObj[key]
});
}
this.deviceList = arr; // Assign a value to the array deviceList, Render to page
<el-form-item
label=" Alarm type "
prop="roomNumber"
>
<el-select
placeholder=" Please select "
clearable
default-first-option
v-model="formInline.alarmDeviceType"
@change="onSearch"
>
<el-option
v-for="(list,k) in deviceList" // Render array to page
:key="k"
:label="list.label"
:value="list.value"
></el-option>
</el-select>
</el-form-item>
3、 ... and 、 final result

That's all for sharing , If it helps you , Don't forget to Fabulous Oh !
边栏推荐
- Prim 最小生成树(图解)
- Stm32+hc05 serial port Bluetooth design simple Bluetooth speaker
- MySQL takes the query result as the data updated by update, and concatenates it after the original field data (Lej)
- How to write Android switching interface with kotlin
- [selected] from simple to deep, you will understand MQ principles and application scenarios
- [De1CTF 2019]SSRF Me
- Numpy- array属性、改变形状函数、基本运算
- 【代码源】每日一题 分割(nlogn&n解法)
- ~2 ccf 2022-03-1 未初始化警告
- Data query language (DQL)
猜你喜欢

¥1-2 例2.2 将两个集合的并集放到线性表中
![[GYCTF2020]Node Game](/img/8d/7e6c2fb2a0359298fbcc1cd8544710.png)
[GYCTF2020]Node Game

idea 热部署

Idea practical tips --- now change pom.xml (red) to pom.xml (blue)

The jar package has been launched on Alibaba cloud server and the security group has been opened, but postman still can't run. What should we do

变量名可以用中文?直接把人干蒙了

OC--Foundation--数组

OC--Foundation--字典

粗柳簸箕细柳斗,谁嫌爬虫男人丑 之 异步协程半秒扒光一本小说
![[De1CTF 2019]SSRF Me](/img/12/44c37cc713b49172a10579c9628c94.png)
[De1CTF 2019]SSRF Me
随机推荐
【代码源】每日一题 分割(nlogn&n解法)
Two Sum
sqli-labs Basic Challenges Less1-10
Go基础4
Data query language (DQL)
Interviewer: tell me the difference between redis and mongodb? [easy to understand]
Numpy - Construction of array
Basic network knowledge
How to write Android switching interface with kotlin
单例模式(Singleton)
Jspdf generates PDF files. There is a problem of incomplete files. Files are downloaded in the background, but not in the foreground
~5 ccf 2021-12-2 序列查询新解
OverTheWire-Natas
Unable to start debugging on the web server, the web server failed to find the requested resource
梦想启航(第一篇博客)
【代码源】每日一题 - 排队
@1-1 CCF 2021-04-1 灰度直方图
How to deploy the jar package to the server? Note: whether the startup command has nohup or not has a lot to do with it
uni-app如何获取位置信息(经纬度)
¥1-2 例2.2 将两个集合的并集放到线性表中