const matchModification = (arrayJsonObj, data) => {
let arrayJsonObjCopy = JSON.stringify(cloneDeep(arrayJsonObj));//cloneDeep lodash中深拷贝方法
data.forEach((item) => {
let reg = new RegExp(item.oldValue, 'g');
arrayJsonObjCopy = arrayJsonObjCopy.replace(reg, item.newValue);
});
return arrayJsonObjCopy;
};
DistrictCityTree_YH().then((res) => {
//由于方法比较通用挂在了vue原型链上
let dictionary_YH = Vue.prototype._format.matchModification(res, [
{ oldValue: 'regionName', newValue: 'label' },
{ oldValue: 'regionCode', newValue: 'value' }
]);
});
效果展示
转换前:
转换后: