`toArray` function would be very handy
geoidesic opened this issue · comments
Noel da Costa commented
Many components expect an array, whereas jv/get
returns an object containing objects. It would be really handy to have a way of quickly turning that into an array of objects, each of which includes the attributes. e.g.
echo this.$store.getters["jv/get"]("enquiries").toArray();
should output
[
{
id: 1,
name: 'one'
},
{
id: 2,
name: 'two'
},
]
I'm having to do this at the moment but I suspect that it could be done more efficiently if it didn't rely on first doing get
.
let data = [];
_.each(this.$store.getters["jv/get"]("enquiries"), (id, val) => {
let record = val._jv.attrs;
record.id = id;
data.push(record);
});
Matthew Richardson commented
You can get this as a one-liner by doing:
Object.values(this.$store.getters["jv/get"]("enquiries"))
This will return an array of the values of an object - i.e the nested objects.
Noel da Costa commented
That won't contain the id
column, will it? But I guess I can get that via _jv
property.