Adding Value To Search Result From Json Resp
Currently I am having the list of titles generating with below logic, Now I want to add data to the title list + code of that title from response data const title = responseData.ma
Solution 1:
you can get code like this :
const title = responseData.map(item => {
return { label:`${item.title}${item.regisration[0].registration_type.code}`,
value: item._id };
});
this is only for first element in registration!
here registration is array if you want to get each registration use map method too, this example like your code:
let options= [{
id:1,
registration:[
{
registration_type:{
id:1,
code:"fo"
}
},
{
registration_type:{
id:2,
code:"fox"
}
}
],
title:"hello world"
}
]
options.map(data=>{
data.registration.map(reg=>{
console.log(`${data.title}${reg.registration_type.code}`)
})
})
Solution 2:
If you mean you want output something like this
{
_id:asadadd,
code:"OF",
title:"abc"
}
you can code Object.assign({data:{title:"abc"}})
Solution 3:
Check this I'm not sure maybe this code will help you
const title = responseData.map(item => {
return { label: loopingResult(item), value: item._id };
});
functionloopingResult(item) {
for (var i = 0; i < item.registration.length; i++) {
const result = `${item.title}${item.registration[i].registration_type.code}`;
return result.split(',');
}
}
Post a Comment for "Adding Value To Search Result From Json Resp"