1

How can I retrieve the data from a data object in Vue?

I have data in this format:

datasets: [{
 text:"Cars",
 value: "[1,2,3]" 
},
{
 text:"Trains",
 value: "[1,4,10]
}
]

Now I from route props I get the following info:

this.selectedText= this.$route.name;

Where this.$route.name is "Cars" for example. Now I want to take this use this.selectedValue to get corresponding Value from this array: so if this.selectedText="Cars" then this.selectedValue=[1,2,3] or based on this I want to retrieve the value of given text.

1 Answer 1

1

Create a method and use this code to find out the matching one.

function setSelectedValue() {
    let matchingDatSet = this.datasets.find(ele => ele.text == this.selectedText);
    if(matchingDataSet !== undefined) {
        this.selectedValue = matchingDataSet.value;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.