Add span-tags around the text(string), that included in an object











up vote
5
down vote

favorite












Hi I'm trying to change the background color of the text that is included an the object. I'm trying it in vuejs.

I've text(string) and some data(object).

My requirement is, if the word is included in the object. Then I need to change the background color of that particular word.



From the response I'll get the text like this:
text: "Pavan'snPavannKumar Dasireddy isntrying tonaddnthe span tagnto the textn That isn in an Object.".



Calling the nb2html(this.theText) function in the <span id="test" v-html="nb2html(this.text)"> </span> for replacing the n with <br> tag.



After Replacing with <br> I can see the UI as below:
picture after replacing with break



So, when the page loaded the included text should be highlighted with some background color.




sanbox link: Sandbox link




Eg: In the below code, Kumar is included in the object, so I need to change the background color for Kumar only.



I tried mapping the object and checking the text with myObject.includes(${searchText}).
If includes then tried to replace the text with the <span style="background-color: yellow">${searchText}</span>.



But span tag not adding to the text.Here is my code sample:






<template>
<span>
<el-row type="flex">
<el-col>
<el-card>
<span id="test" v-html="nb2html(this.text)">
</span>
</el-card>
</el-col>
</el-row>
</span>
</template>
<script>
export default {
name: 'samplefile',
data() {
return {
theText: '',
text: "Pavan'snPavannKumar Dasireddy isntrying tonaddnthe span tagnto the textn That isn in an Object.",
myObject: {
name: 'Kumar',
trying: 'add',
isGood: 'the text which is on tag form of',
mobile: '9874563210',
concept: 'trying',
user:'Pavan',
}
};
},
watch: {
document: 'caluclateBoundingBoxes',
selectedText: 'hideContextMenu',
},
mounted() {
this.caluclateBoundingBoxes();
},
methods() {
nb2html(text) {
const mainText = text.replace(/n/g, '<br>');
this.theText = mainText;
Object.keys(this.myObject).map((key, index) => {
const searchText = `${this.myObject[key]}`;

const n = this.theText.includes(`${searchText}`);

console.log(`index:${index}`, `${key}: ${searchText}`, n, 'position:', this.theText.indexOf(`${searchText}`), 'length:', searchText.length);

const repText = `<span style="background-color: yellow">${searchText}</span>`;

this.theText = this.theText.replace(/${searchText}/i, repText);
return this.theText;
});
return this.theText;
},
caluclateBoundingBoxes() {
if (this.myObject) {
this.myObject = JSON.parse(JSON.stringify(this.myObject));
console.log('the text is:', this.theText);
console.log(this.myObject);
}
},
}
}
</script>





Please suggest me the possible way to achieve this. Thanks!!










share|improve this question
























  • Since I can't run the snippet, could you add the output of this.theText and this.myObject to the question?
    – peresleguine
    Nov 9 at 10:34










  • @peresleguine,Thanks for the reply, modified the question. Please check it and let me know if need more information.
    – Pavan kumar Dasireddy
    Nov 9 at 10:48

















up vote
5
down vote

favorite












Hi I'm trying to change the background color of the text that is included an the object. I'm trying it in vuejs.

I've text(string) and some data(object).

My requirement is, if the word is included in the object. Then I need to change the background color of that particular word.



From the response I'll get the text like this:
text: "Pavan'snPavannKumar Dasireddy isntrying tonaddnthe span tagnto the textn That isn in an Object.".



Calling the nb2html(this.theText) function in the <span id="test" v-html="nb2html(this.text)"> </span> for replacing the n with <br> tag.



After Replacing with <br> I can see the UI as below:
picture after replacing with break



So, when the page loaded the included text should be highlighted with some background color.




sanbox link: Sandbox link




Eg: In the below code, Kumar is included in the object, so I need to change the background color for Kumar only.



I tried mapping the object and checking the text with myObject.includes(${searchText}).
If includes then tried to replace the text with the <span style="background-color: yellow">${searchText}</span>.



But span tag not adding to the text.Here is my code sample:






<template>
<span>
<el-row type="flex">
<el-col>
<el-card>
<span id="test" v-html="nb2html(this.text)">
</span>
</el-card>
</el-col>
</el-row>
</span>
</template>
<script>
export default {
name: 'samplefile',
data() {
return {
theText: '',
text: "Pavan'snPavannKumar Dasireddy isntrying tonaddnthe span tagnto the textn That isn in an Object.",
myObject: {
name: 'Kumar',
trying: 'add',
isGood: 'the text which is on tag form of',
mobile: '9874563210',
concept: 'trying',
user:'Pavan',
}
};
},
watch: {
document: 'caluclateBoundingBoxes',
selectedText: 'hideContextMenu',
},
mounted() {
this.caluclateBoundingBoxes();
},
methods() {
nb2html(text) {
const mainText = text.replace(/n/g, '<br>');
this.theText = mainText;
Object.keys(this.myObject).map((key, index) => {
const searchText = `${this.myObject[key]}`;

const n = this.theText.includes(`${searchText}`);

console.log(`index:${index}`, `${key}: ${searchText}`, n, 'position:', this.theText.indexOf(`${searchText}`), 'length:', searchText.length);

const repText = `<span style="background-color: yellow">${searchText}</span>`;

this.theText = this.theText.replace(/${searchText}/i, repText);
return this.theText;
});
return this.theText;
},
caluclateBoundingBoxes() {
if (this.myObject) {
this.myObject = JSON.parse(JSON.stringify(this.myObject));
console.log('the text is:', this.theText);
console.log(this.myObject);
}
},
}
}
</script>





Please suggest me the possible way to achieve this. Thanks!!










share|improve this question
























  • Since I can't run the snippet, could you add the output of this.theText and this.myObject to the question?
    – peresleguine
    Nov 9 at 10:34










  • @peresleguine,Thanks for the reply, modified the question. Please check it and let me know if need more information.
    – Pavan kumar Dasireddy
    Nov 9 at 10:48















up vote
5
down vote

favorite









up vote
5
down vote

favorite











Hi I'm trying to change the background color of the text that is included an the object. I'm trying it in vuejs.

I've text(string) and some data(object).

My requirement is, if the word is included in the object. Then I need to change the background color of that particular word.



From the response I'll get the text like this:
text: "Pavan'snPavannKumar Dasireddy isntrying tonaddnthe span tagnto the textn That isn in an Object.".



Calling the nb2html(this.theText) function in the <span id="test" v-html="nb2html(this.text)"> </span> for replacing the n with <br> tag.



After Replacing with <br> I can see the UI as below:
picture after replacing with break



So, when the page loaded the included text should be highlighted with some background color.




sanbox link: Sandbox link




Eg: In the below code, Kumar is included in the object, so I need to change the background color for Kumar only.



I tried mapping the object and checking the text with myObject.includes(${searchText}).
If includes then tried to replace the text with the <span style="background-color: yellow">${searchText}</span>.



But span tag not adding to the text.Here is my code sample:






<template>
<span>
<el-row type="flex">
<el-col>
<el-card>
<span id="test" v-html="nb2html(this.text)">
</span>
</el-card>
</el-col>
</el-row>
</span>
</template>
<script>
export default {
name: 'samplefile',
data() {
return {
theText: '',
text: "Pavan'snPavannKumar Dasireddy isntrying tonaddnthe span tagnto the textn That isn in an Object.",
myObject: {
name: 'Kumar',
trying: 'add',
isGood: 'the text which is on tag form of',
mobile: '9874563210',
concept: 'trying',
user:'Pavan',
}
};
},
watch: {
document: 'caluclateBoundingBoxes',
selectedText: 'hideContextMenu',
},
mounted() {
this.caluclateBoundingBoxes();
},
methods() {
nb2html(text) {
const mainText = text.replace(/n/g, '<br>');
this.theText = mainText;
Object.keys(this.myObject).map((key, index) => {
const searchText = `${this.myObject[key]}`;

const n = this.theText.includes(`${searchText}`);

console.log(`index:${index}`, `${key}: ${searchText}`, n, 'position:', this.theText.indexOf(`${searchText}`), 'length:', searchText.length);

const repText = `<span style="background-color: yellow">${searchText}</span>`;

this.theText = this.theText.replace(/${searchText}/i, repText);
return this.theText;
});
return this.theText;
},
caluclateBoundingBoxes() {
if (this.myObject) {
this.myObject = JSON.parse(JSON.stringify(this.myObject));
console.log('the text is:', this.theText);
console.log(this.myObject);
}
},
}
}
</script>





Please suggest me the possible way to achieve this. Thanks!!










share|improve this question















Hi I'm trying to change the background color of the text that is included an the object. I'm trying it in vuejs.

I've text(string) and some data(object).

My requirement is, if the word is included in the object. Then I need to change the background color of that particular word.



From the response I'll get the text like this:
text: "Pavan'snPavannKumar Dasireddy isntrying tonaddnthe span tagnto the textn That isn in an Object.".



Calling the nb2html(this.theText) function in the <span id="test" v-html="nb2html(this.text)"> </span> for replacing the n with <br> tag.



After Replacing with <br> I can see the UI as below:
picture after replacing with break



So, when the page loaded the included text should be highlighted with some background color.




sanbox link: Sandbox link




Eg: In the below code, Kumar is included in the object, so I need to change the background color for Kumar only.



I tried mapping the object and checking the text with myObject.includes(${searchText}).
If includes then tried to replace the text with the <span style="background-color: yellow">${searchText}</span>.



But span tag not adding to the text.Here is my code sample:






<template>
<span>
<el-row type="flex">
<el-col>
<el-card>
<span id="test" v-html="nb2html(this.text)">
</span>
</el-card>
</el-col>
</el-row>
</span>
</template>
<script>
export default {
name: 'samplefile',
data() {
return {
theText: '',
text: "Pavan'snPavannKumar Dasireddy isntrying tonaddnthe span tagnto the textn That isn in an Object.",
myObject: {
name: 'Kumar',
trying: 'add',
isGood: 'the text which is on tag form of',
mobile: '9874563210',
concept: 'trying',
user:'Pavan',
}
};
},
watch: {
document: 'caluclateBoundingBoxes',
selectedText: 'hideContextMenu',
},
mounted() {
this.caluclateBoundingBoxes();
},
methods() {
nb2html(text) {
const mainText = text.replace(/n/g, '<br>');
this.theText = mainText;
Object.keys(this.myObject).map((key, index) => {
const searchText = `${this.myObject[key]}`;

const n = this.theText.includes(`${searchText}`);

console.log(`index:${index}`, `${key}: ${searchText}`, n, 'position:', this.theText.indexOf(`${searchText}`), 'length:', searchText.length);

const repText = `<span style="background-color: yellow">${searchText}</span>`;

this.theText = this.theText.replace(/${searchText}/i, repText);
return this.theText;
});
return this.theText;
},
caluclateBoundingBoxes() {
if (this.myObject) {
this.myObject = JSON.parse(JSON.stringify(this.myObject));
console.log('the text is:', this.theText);
console.log(this.myObject);
}
},
}
}
</script>





Please suggest me the possible way to achieve this. Thanks!!






<template>
<span>
<el-row type="flex">
<el-col>
<el-card>
<span id="test" v-html="nb2html(this.text)">
</span>
</el-card>
</el-col>
</el-row>
</span>
</template>
<script>
export default {
name: 'samplefile',
data() {
return {
theText: '',
text: "Pavan'snPavannKumar Dasireddy isntrying tonaddnthe span tagnto the textn That isn in an Object.",
myObject: {
name: 'Kumar',
trying: 'add',
isGood: 'the text which is on tag form of',
mobile: '9874563210',
concept: 'trying',
user:'Pavan',
}
};
},
watch: {
document: 'caluclateBoundingBoxes',
selectedText: 'hideContextMenu',
},
mounted() {
this.caluclateBoundingBoxes();
},
methods() {
nb2html(text) {
const mainText = text.replace(/n/g, '<br>');
this.theText = mainText;
Object.keys(this.myObject).map((key, index) => {
const searchText = `${this.myObject[key]}`;

const n = this.theText.includes(`${searchText}`);

console.log(`index:${index}`, `${key}: ${searchText}`, n, 'position:', this.theText.indexOf(`${searchText}`), 'length:', searchText.length);

const repText = `<span style="background-color: yellow">${searchText}</span>`;

this.theText = this.theText.replace(/${searchText}/i, repText);
return this.theText;
});
return this.theText;
},
caluclateBoundingBoxes() {
if (this.myObject) {
this.myObject = JSON.parse(JSON.stringify(this.myObject));
console.log('the text is:', this.theText);
console.log(this.myObject);
}
},
}
}
</script>





<template>
<span>
<el-row type="flex">
<el-col>
<el-card>
<span id="test" v-html="nb2html(this.text)">
</span>
</el-card>
</el-col>
</el-row>
</span>
</template>
<script>
export default {
name: 'samplefile',
data() {
return {
theText: '',
text: "Pavan'snPavannKumar Dasireddy isntrying tonaddnthe span tagnto the textn That isn in an Object.",
myObject: {
name: 'Kumar',
trying: 'add',
isGood: 'the text which is on tag form of',
mobile: '9874563210',
concept: 'trying',
user:'Pavan',
}
};
},
watch: {
document: 'caluclateBoundingBoxes',
selectedText: 'hideContextMenu',
},
mounted() {
this.caluclateBoundingBoxes();
},
methods() {
nb2html(text) {
const mainText = text.replace(/n/g, '<br>');
this.theText = mainText;
Object.keys(this.myObject).map((key, index) => {
const searchText = `${this.myObject[key]}`;

const n = this.theText.includes(`${searchText}`);

console.log(`index:${index}`, `${key}: ${searchText}`, n, 'position:', this.theText.indexOf(`${searchText}`), 'length:', searchText.length);

const repText = `<span style="background-color: yellow">${searchText}</span>`;

this.theText = this.theText.replace(/${searchText}/i, repText);
return this.theText;
});
return this.theText;
},
caluclateBoundingBoxes() {
if (this.myObject) {
this.myObject = JSON.parse(JSON.stringify(this.myObject));
console.log('the text is:', this.theText);
console.log(this.myObject);
}
},
}
}
</script>






javascript html css vue.js wrapping






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 at 6:47

























asked Nov 9 at 10:12









Pavan kumar Dasireddy

404112




404112












  • Since I can't run the snippet, could you add the output of this.theText and this.myObject to the question?
    – peresleguine
    Nov 9 at 10:34










  • @peresleguine,Thanks for the reply, modified the question. Please check it and let me know if need more information.
    – Pavan kumar Dasireddy
    Nov 9 at 10:48




















  • Since I can't run the snippet, could you add the output of this.theText and this.myObject to the question?
    – peresleguine
    Nov 9 at 10:34










  • @peresleguine,Thanks for the reply, modified the question. Please check it and let me know if need more information.
    – Pavan kumar Dasireddy
    Nov 9 at 10:48


















Since I can't run the snippet, could you add the output of this.theText and this.myObject to the question?
– peresleguine
Nov 9 at 10:34




Since I can't run the snippet, could you add the output of this.theText and this.myObject to the question?
– peresleguine
Nov 9 at 10:34












@peresleguine,Thanks for the reply, modified the question. Please check it and let me know if need more information.
– Pavan kumar Dasireddy
Nov 9 at 10:48






@peresleguine,Thanks for the reply, modified the question. Please check it and let me know if need more information.
– Pavan kumar Dasireddy
Nov 9 at 10:48














2 Answers
2






active

oldest

votes

















up vote
0
down vote













I don't use vue.js here and perhaps you have different logic, but hopefully this plain javascript snippet could help:






var myText = "Pavan's Pavan Kumar Dasireddy is trying to add the span tag to the text that is in an Object."

var myObject = {
name: 'Kumar',
trying: 'add',
isGood: 'the text which is on tag form of',
mobile: '9874563210',
concept: 'trying',
user:'Pavan'
}

var result = myText.split(' ').map(function(word) {
if (Object.values(myObject).includes(word)) {
return '<span class="yellow">' + word + '</span>'
} else {
return word
}
})

var e = document.getElementById('result')
e.innerHTML = result.join(' ')

.yellow {
background-color: yellow;
}

<div id="result"></div>





If the above snippet is unavailable check this codepen.






share|improve this answer























  • Please check my sanbox once: codesandbox.io/s/z66jzp0x74
    – Pavan kumar Dasireddy
    Nov 9 at 11:36












  • @PavankumarDasireddy, sorry, I've not tried Vue yet but I'm sure you can adapt plain javascript for your use case.
    – peresleguine
    Nov 9 at 11:59










  • Thanks @peresleguine, for your valuable time and for the code.
    – Pavan kumar Dasireddy
    Nov 9 at 12:07




















up vote
0
down vote













Adding this as a second argument to map should fix this:



Object.keys(this.myObject).map((key, index) => {
...
}, this)


There is a scope issue where the this in map declaration is not scoped to the Vue component.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53223732%2fadd-span-tags-around-the-textstring-that-included-in-an-object%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    I don't use vue.js here and perhaps you have different logic, but hopefully this plain javascript snippet could help:






    var myText = "Pavan's Pavan Kumar Dasireddy is trying to add the span tag to the text that is in an Object."

    var myObject = {
    name: 'Kumar',
    trying: 'add',
    isGood: 'the text which is on tag form of',
    mobile: '9874563210',
    concept: 'trying',
    user:'Pavan'
    }

    var result = myText.split(' ').map(function(word) {
    if (Object.values(myObject).includes(word)) {
    return '<span class="yellow">' + word + '</span>'
    } else {
    return word
    }
    })

    var e = document.getElementById('result')
    e.innerHTML = result.join(' ')

    .yellow {
    background-color: yellow;
    }

    <div id="result"></div>





    If the above snippet is unavailable check this codepen.






    share|improve this answer























    • Please check my sanbox once: codesandbox.io/s/z66jzp0x74
      – Pavan kumar Dasireddy
      Nov 9 at 11:36












    • @PavankumarDasireddy, sorry, I've not tried Vue yet but I'm sure you can adapt plain javascript for your use case.
      – peresleguine
      Nov 9 at 11:59










    • Thanks @peresleguine, for your valuable time and for the code.
      – Pavan kumar Dasireddy
      Nov 9 at 12:07

















    up vote
    0
    down vote













    I don't use vue.js here and perhaps you have different logic, but hopefully this plain javascript snippet could help:






    var myText = "Pavan's Pavan Kumar Dasireddy is trying to add the span tag to the text that is in an Object."

    var myObject = {
    name: 'Kumar',
    trying: 'add',
    isGood: 'the text which is on tag form of',
    mobile: '9874563210',
    concept: 'trying',
    user:'Pavan'
    }

    var result = myText.split(' ').map(function(word) {
    if (Object.values(myObject).includes(word)) {
    return '<span class="yellow">' + word + '</span>'
    } else {
    return word
    }
    })

    var e = document.getElementById('result')
    e.innerHTML = result.join(' ')

    .yellow {
    background-color: yellow;
    }

    <div id="result"></div>





    If the above snippet is unavailable check this codepen.






    share|improve this answer























    • Please check my sanbox once: codesandbox.io/s/z66jzp0x74
      – Pavan kumar Dasireddy
      Nov 9 at 11:36












    • @PavankumarDasireddy, sorry, I've not tried Vue yet but I'm sure you can adapt plain javascript for your use case.
      – peresleguine
      Nov 9 at 11:59










    • Thanks @peresleguine, for your valuable time and for the code.
      – Pavan kumar Dasireddy
      Nov 9 at 12:07















    up vote
    0
    down vote










    up vote
    0
    down vote









    I don't use vue.js here and perhaps you have different logic, but hopefully this plain javascript snippet could help:






    var myText = "Pavan's Pavan Kumar Dasireddy is trying to add the span tag to the text that is in an Object."

    var myObject = {
    name: 'Kumar',
    trying: 'add',
    isGood: 'the text which is on tag form of',
    mobile: '9874563210',
    concept: 'trying',
    user:'Pavan'
    }

    var result = myText.split(' ').map(function(word) {
    if (Object.values(myObject).includes(word)) {
    return '<span class="yellow">' + word + '</span>'
    } else {
    return word
    }
    })

    var e = document.getElementById('result')
    e.innerHTML = result.join(' ')

    .yellow {
    background-color: yellow;
    }

    <div id="result"></div>





    If the above snippet is unavailable check this codepen.






    share|improve this answer














    I don't use vue.js here and perhaps you have different logic, but hopefully this plain javascript snippet could help:






    var myText = "Pavan's Pavan Kumar Dasireddy is trying to add the span tag to the text that is in an Object."

    var myObject = {
    name: 'Kumar',
    trying: 'add',
    isGood: 'the text which is on tag form of',
    mobile: '9874563210',
    concept: 'trying',
    user:'Pavan'
    }

    var result = myText.split(' ').map(function(word) {
    if (Object.values(myObject).includes(word)) {
    return '<span class="yellow">' + word + '</span>'
    } else {
    return word
    }
    })

    var e = document.getElementById('result')
    e.innerHTML = result.join(' ')

    .yellow {
    background-color: yellow;
    }

    <div id="result"></div>





    If the above snippet is unavailable check this codepen.






    var myText = "Pavan's Pavan Kumar Dasireddy is trying to add the span tag to the text that is in an Object."

    var myObject = {
    name: 'Kumar',
    trying: 'add',
    isGood: 'the text which is on tag form of',
    mobile: '9874563210',
    concept: 'trying',
    user:'Pavan'
    }

    var result = myText.split(' ').map(function(word) {
    if (Object.values(myObject).includes(word)) {
    return '<span class="yellow">' + word + '</span>'
    } else {
    return word
    }
    })

    var e = document.getElementById('result')
    e.innerHTML = result.join(' ')

    .yellow {
    background-color: yellow;
    }

    <div id="result"></div>





    var myText = "Pavan's Pavan Kumar Dasireddy is trying to add the span tag to the text that is in an Object."

    var myObject = {
    name: 'Kumar',
    trying: 'add',
    isGood: 'the text which is on tag form of',
    mobile: '9874563210',
    concept: 'trying',
    user:'Pavan'
    }

    var result = myText.split(' ').map(function(word) {
    if (Object.values(myObject).includes(word)) {
    return '<span class="yellow">' + word + '</span>'
    } else {
    return word
    }
    })

    var e = document.getElementById('result')
    e.innerHTML = result.join(' ')

    .yellow {
    background-color: yellow;
    }

    <div id="result"></div>






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 9 at 11:35

























    answered Nov 9 at 11:28









    peresleguine

    1,51822227




    1,51822227












    • Please check my sanbox once: codesandbox.io/s/z66jzp0x74
      – Pavan kumar Dasireddy
      Nov 9 at 11:36












    • @PavankumarDasireddy, sorry, I've not tried Vue yet but I'm sure you can adapt plain javascript for your use case.
      – peresleguine
      Nov 9 at 11:59










    • Thanks @peresleguine, for your valuable time and for the code.
      – Pavan kumar Dasireddy
      Nov 9 at 12:07




















    • Please check my sanbox once: codesandbox.io/s/z66jzp0x74
      – Pavan kumar Dasireddy
      Nov 9 at 11:36












    • @PavankumarDasireddy, sorry, I've not tried Vue yet but I'm sure you can adapt plain javascript for your use case.
      – peresleguine
      Nov 9 at 11:59










    • Thanks @peresleguine, for your valuable time and for the code.
      – Pavan kumar Dasireddy
      Nov 9 at 12:07


















    Please check my sanbox once: codesandbox.io/s/z66jzp0x74
    – Pavan kumar Dasireddy
    Nov 9 at 11:36






    Please check my sanbox once: codesandbox.io/s/z66jzp0x74
    – Pavan kumar Dasireddy
    Nov 9 at 11:36














    @PavankumarDasireddy, sorry, I've not tried Vue yet but I'm sure you can adapt plain javascript for your use case.
    – peresleguine
    Nov 9 at 11:59




    @PavankumarDasireddy, sorry, I've not tried Vue yet but I'm sure you can adapt plain javascript for your use case.
    – peresleguine
    Nov 9 at 11:59












    Thanks @peresleguine, for your valuable time and for the code.
    – Pavan kumar Dasireddy
    Nov 9 at 12:07






    Thanks @peresleguine, for your valuable time and for the code.
    – Pavan kumar Dasireddy
    Nov 9 at 12:07














    up vote
    0
    down vote













    Adding this as a second argument to map should fix this:



    Object.keys(this.myObject).map((key, index) => {
    ...
    }, this)


    There is a scope issue where the this in map declaration is not scoped to the Vue component.






    share|improve this answer



























      up vote
      0
      down vote













      Adding this as a second argument to map should fix this:



      Object.keys(this.myObject).map((key, index) => {
      ...
      }, this)


      There is a scope issue where the this in map declaration is not scoped to the Vue component.






      share|improve this answer

























        up vote
        0
        down vote










        up vote
        0
        down vote









        Adding this as a second argument to map should fix this:



        Object.keys(this.myObject).map((key, index) => {
        ...
        }, this)


        There is a scope issue where the this in map declaration is not scoped to the Vue component.






        share|improve this answer














        Adding this as a second argument to map should fix this:



        Object.keys(this.myObject).map((key, index) => {
        ...
        }, this)


        There is a scope issue where the this in map declaration is not scoped to the Vue component.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 9 at 13:49

























        answered Nov 9 at 10:36









        Shawn Janas

        1,86811010




        1,86811010






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53223732%2fadd-span-tags-around-the-textstring-that-included-in-an-object%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Schultheiß

            Verwaltungsgliederung Dänemarks

            Liste der Kulturdenkmale in Wilsdruff