У меня есть проблема, которую я не могу решить долгое время. У меня есть два вложенных объекта JSON, и мне нужно узнать, что является дополнениями во втором и выделить их (добавить класс CSS).
Например, если у меня было:
let obj1 = {
blocks: [
{
type: 'paragraph',
data: {
text: 'This is text for my project.',
},
},
{
type: 'paragraph',
data: {
text: 'This is in both and needs no change',
},
},
],
}
let obj2 = {
blocks: [
{
type: 'paragraph',
data: {
text:
'This is text for my project. This is some text that will not be in the first object.',
},
},
{
type: 'paragraph',
data: {
text: 'Things are becoming complicated in programming',
},
},
{
type: 'paragraph',
data: {
text: 'This is in both and needs no change',
},
},
],
}
После их сравнения я бы хотел, чтобы второй объект был похож на:
let obj2 = {
blocks: [
{
type: 'paragraph',
data: {
text:
'This is text for my project. <span class="new-text">This is some text that will not be in the first object.</span>',
},
},
{
type: 'paragraph',
data: {
text: '<span class="new-text">Things are becoming complicated in programming</span>',
},
},
{
type: 'paragraph',
data: {
text: 'This is in both and needs no change',
},
},
],
}
Я попытался просмотреть библиотеку diff из Google, но не могу найти другие вещи, которые могут быть чистыми строками или обычные объекты (не вложенные)
Любая помощь приветствуется.
Спасибо!