echart merging configuration items

Recent echart do data visualization, met a demand, is the need to merge the default configuration item data items and returned backstage. The first time the thought of directly using native JavaScript is Object.assign to deal with, echart deeper level configuration items, with Object.assign not fit. The Internet to find a lot of methods, failed to solve a problem, the merger is an array of objects under comparison array failed to retain the energy field. Later, remembering the powerful lodash , its merge method is fully in line with their needs.

I just want to use the merge method alone, can be installed directly lodash.merge package

npm i lodash.merge

use

import merge from 'lodash.merge'
// ......
merge({},defaultOption,otherOption,dataOption)
// ......

Note: all the configuration items to merge without defaultOption as the source, is prevented defaultOption is changed after the merger,

Guess you like

Origin www.cnblogs.com/teemwu/p/12053248.html