当前位置:网站首页>递归检查配置项是否更变并替换
递归检查配置项是否更变并替换
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]
})
}
边栏推荐
猜你喜欢

Oracle19c安装图文教程

记一次gorm事务及调试解决mysql死锁

四元数、罗德里格斯公式、欧拉角、旋转矩阵推导和资料

CASE2023

The failure to create a role in Dahua Westward Journey has been solved

A good book for newcomers to the workplace

【web】Understanding Cookie and Session Mechanism

nacos startup error, the database has been configured, stand-alone startup

【Unity入门计划】2D Game Kit:初步了解2D游戏组成

Good News | AR opens a new model for the textile industry, and ALVA Systems wins another award!
随机推荐
极大似然估计
C#测试项目中属性的用法
一次SQL优化,数据库查询速度提升 60 倍
Analysis of the status quo of digital transformation of manufacturing enterprises
【 wheeled odometer 】
考完PMP学什么?前方软考等着你~
罗德里格斯公式(Rodrigues‘ Rotation Formula)推导
JVM调优实战
29. 删除链表中重复的节点
BI - SQL 丨 WHILE
简单的页面跳转活动
Flask入门学习教程
局部敏感哈希:如何在常数时间内搜索Embedding最近邻
PHP live source code to achieve simple barrage effect related code
pyqt上手体验
Unable to log in to the Westward Journey
网络层解析——IP协议、地址管理、路由选择
NIO‘s Sword(牛客多校赛)
架构:应用架构的演进以及微服务架构的落地实践
Use DBeaver for mysql data backup and recovery