Some basic information about what I’m working on. For sake of me trying to figure this out and not disclosing all information, I will input necessary info to understand the problem. This is using VUE JS.
I’m trying to update a button’s text with a method called text –> {{ text }} //
Here’s what I’m working with:
someName: [
{
someKey: "someValue"
},
{
someKey: "notSomeValue"
},
My text method is inside of the computed properties section and is written as so:
text() {
return this.someName.filter(u => {
return u.someKey === "someValue" ? "turn off" : "turn on";
})
It is not posting the strings and is instead showing the objects as the button text. What am I not understanding?
I have also tried storing the string value inside a data property and displaying that. Also did not work. I’d expect the text to be one of the two string values inside of the conditional statement.
3
Answers
You can modify your text methods like this,you return a array which should return a string
You can use Array.find for a one line solution.
You can simply achieve this with the help of
Array.some()
method as It will return true if any of the objects ofsomeName
array containssomeValue
and then based on that we can return the button text.Live Demo :