当前位置:网站首页>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 !
边栏推荐
- sqli-labs Basic Challenges Less1-10
- Machine learning -- detailed introduction of standardscaler (), transform (), fit () in sklearn package
- 【cf】Round 128 C. Binary String
- Read and write mongodb database files
- In mysql, update and select are used together
- [HCTF 2018]admin
- 初始Flask以及简单地上手应用
- The interviewer asked: how to prevent oversold? There are several ways to achieve it
- Flex 布局语法与用例
- SSM框架整合,简单案例
猜你喜欢

作业7.15 shell脚本

uni-app如何获取位置信息(经纬度)

Redis string 结构命令

~3 ccf 2022-03-2 出行计划

最短路问题 Bellman-Ford(单源最短路径)(图解)

Jspdf generates PDF files. There is a problem of incomplete files. Files are downloaded in the background, but not in the foreground

如何将Jar包部署到服务器,注:启动命令有无nohup有很大关系

Detailed explanation of the use of nanny scanner class
![[GYCTF2020]Node Game](/img/8d/7e6c2fb2a0359298fbcc1cd8544710.png)
[GYCTF2020]Node Game

What are stand-alone, cluster and distributed?
随机推荐
&lt; T&gt; Generic method demonstration
What is the difference between mongodb and redis
Click to hide the column in wechat applet, and then click to show it
[De1CTF 2019]SSRF Me
Redis set 结构命令
【代码源】每日一题 农田划分
单例模式(Singleton)
Read and write mongodb database files
SSM框架整合,简单案例
Flex 布局语法与用例
Excl batch import data, background public parsing method
Understand why we should rewrite the equals method and hashcode method at the same time + example analysis
OC--Foundation--数组
最短路问题 Bellman-Ford(单源最短路径)(图解)
[GKCTF 2021]easynode
~5 ccf 2021-12-2 序列查询新解
@3-2 CCF 2020-12-2 期末预测之最佳阈值
~2 ccf 2022-03-1 未初始化警告
sqli-labs安装 环境:ubuntu18 php7
Week summary