[英]How to create interface adapter in typescript?
I want to replace client json into my json我想将客户 json 替换为我的 json
client JSON客户 JSON
interface Cols {
displayName: string;
}
{
cols:[
{
displayName: 'abc';
}
]
}
my JSON我的 JSON
interface Cols {
label: string;
}
{
cols:[
{
label:'z';
}
]
}
I want to replace z into abc我想把 z 换成 abc
to replace your value directly,直接替换你的值,
const a = {
cols:[
{
label:'z'
}
]
}
a.cols[0].label = 'abc'
from client json you wanted to replace with ypu can use:从客户 json 你想用 ypu 替换可以使用:
const a = {
cols:[
{
label:'z'
}
]
}
//clients json
const b = {
cols:[
{
displayName: 'def'
}
]
}
//for static array
a.cols[0].label = b.cols[0].displayName
for more than 1 item in array, you need to put it in a loop or map对于数组中的一项以上,您需要将其放入循环或 map
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.