问题描述
我有一个嵌套的 json 对象,我有一个路径列表(下面给出了模式),我想根据路径动态更改一些值,其余对象保持不变。 我们有样本数据:
export const newTemplate = {
"patientInfo": {
"name": ".document.author.name.given","address": [
{
"country": "pakistan","city": "rawalpindi","disease": [
{
"id": 'HX-12',"name": "Flu"
},{
"id": 'HX-12',"name": "Fever"
}
]
}
],"phone": ".document.author.phone","document": {
"name": ".document.documentation_of[0].name"
}
},"location": ".document.location","allergies": ".allergies","commonInfo": {
"common": {
"allergies": ".allergies",}
}
}
我们有一条路
const path = .patientInfo.address[0].disease[1].name
我想用这条路把“名字”发烧改为Dhairiya
`${newTemplate}${path}` = "Dhairiya"
// it will become like this.
// newTemplate.patientInfo.address[0].disease[1].name = "Dhairiya"
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)