I am using Firebase. There data is stored as objects with unique keys.
I want to keep these keys for updating purposes.
However I also want to sort the data like an array, when rendering it in my Vue-templates.
The data looks like:
topics:
- [firebase-push-key]
- title
- text
- ...
I want to sort it in my template like:
<template v-for="topic in $store.state.forum.topics">
...
</template>
$store.state.forum.topics
should be sorted by the value title
.
EDIT:
This Vuex-mutation does the job:
retrieveTopics(state) {
topics.on('value', (snapshot) => {
const object = snapshot.val()
var array = Object.keys(object).map((key) => {
return { [key]: object[key] }
})
state.forum.topics = array
})
}
But how can I iterate over the resulting array in a vue template?
this is the data structure:
[ { "-Kmbspn0WYBlNXfmfVlR": { "slug": "arne", "title": "Arne" } }, { "-KmbsqiG_9uXzRhHrnXZ": { "slug": "tati", "title": "Tati" } }, { "-KmbsrllgJzV7BA_NeCO": { "slug": "abel", "title": "Abel" } } ]