Reputation: 1747
I have the following object and string variable passed in vue
's props:
catId
:
"51bd55834e8d79bfd458ff8a156e3c11"
categories
:
{
"51bd55834e8d79bfd458ff8a156e3c11": {
"header": "Header One",
".key": "51bd55834e8d79bfd458ff8a156e3c11"
},
"eb4312829f9c57b55727b4d8c6ca1ec7": {
"typeId": "ba86f15d5b2126ac3d0ad39feeb5f400",
"header": "Header Two",
".key": "eb4312829f9c57b55727b4d8c6ca1ec7"
}
}
How can I access the header
parameter of the given category?
I tried the following...
{{categories[this.catId].header}}
...but it does not work.
Upvotes: 0
Views: 39
Reputation: 7187
Seems that you're using text interpolation with mustaches. In that case I don't think you need this
. Try ..
{{categories['catId'].header}}
Upvotes: 3
Reputation: 33206
Seems to work fine.
var id = "51bd55834e8d79bfd458ff8a156e3c11"
var categories = {
"51bd55834e8d79bfd458ff8a156e3c11": {
"header": "Header One",
".key": "51bd55834e8d79bfd458ff8a156e3c11"
},
"eb4312829f9c57b55727b4d8c6ca1ec7": {
"typeId": "ba86f15d5b2126ac3d0ad39feeb5f400",
"header": "Header Two",
".key": "eb4312829f9c57b55727b4d8c6ca1ec7"
}
};
console.log(categories[id].header);
Upvotes: 1