Reputation: 105
{
"_id": "1",
"style": "13123",
"category": "dress",
"colors": {
"Black": {
"prestock": 50,
"instock": 60,
"inactive": 0
},
"Blue": {
"prestock": 30,
"instock": 0,
"inactive": 0
},
"Red": {
"prestock": 10,
"instock": 60,
"inactive": 0
}
}
}
i'm using swig-template to access 'colors' object i need to express each color in this list-format:
how can i access this json?
ps. i tried other ways but no luck, what i have is {{style_list.colors|sort}} which gives me like this:
Black, Blue, Red
Upvotes: 1
Views: 1500
Reputation: 7156
Use the built-in JavaScript method Object.keys
<ul>
{% for color in Object.keys(colors) %}
<li>{{ color }}</li>
{% endfor %}
</ul>
Upvotes: 2