当前位置:网站首页>递归检查配置项是否更变并替换
递归检查配置项是否更变并替换
2022-08-02 02:39:00 【闲鱼_JavaScript】
介绍
- 配置项有原有配置项的情况下,又不想变动其他的配置又能更改提出来配置。参考 echarts 的配置
- 本文以递归的方式,实现了对象格式检查并替换,数组的话可以跟着规则添加就行;
- 支持相同属性的值以传入的属性值为主;在原配置没有的属性则直接加进去(当前级);
- 根据第三点可以支持 echarts、地图等二次封装配置。
实现代码
const configSet = (config, eCData = echartsComponent.data) => {
if (!config) return;
Object.keys(eCData).forEach(key => {
if (!(key in config)) return
if (Object.prototype.toString.call(config[key]) === '[object Object]') return configSet(config[key], eCData[key])
eCData[key] = config[key]
})
Object.keys(config).forEach(key => {
if (!(key in eCData)) eCData[key] = config[key]
})
}
边栏推荐
猜你喜欢

analog IC layout

Chapter 7 Noise analysis

2022-08-01 mysql/stoonedb slow SQL-Q18 analysis

analog IC layout-Parasitic effects

240...循迹

Service discovery of kubernetes

十字光标太小怎么调节、CAD梦想画图算量技巧

Nanoprobes免疫测定丨FluoroNanogold试剂免疫染色方案

忽晴忽雨

The first time I wrote a programming interview question for Niu Ke: input a string and return the letter with the most occurrences of the string
随机推荐
2022牛客多校四_G M
aws s3上传文件
[Unity entry plan] 2D Game Kit: A preliminary understanding of the composition of 2D games
极大似然估计
网络层解析——IP协议、地址管理、路由选择
四元数、罗德里格斯公式、欧拉角、旋转矩阵推导和资料
* 比较版本号
AI target segmentation capability for fast video cutout without green screen
【web】理解 Cookie 和 Session 机制
第10章_索引优化与查询优化
Talking about the "horizontal, vertical and vertical" development trend of domestic ERP
A good book for newcomers to the workplace
GTK RGB图像绘制
EasyGBS平台播放视频时偶尔出现播放失败是什么原因?
Chapter 7 Noise analysis
Unable to log in to the Westward Journey
Analysis of the status quo of digital transformation of manufacturing enterprises
OC中new和init的区别
项目场景 with ERRTYPE = cudaError CUDA failure 999 unknown error
53. 最小的k个数