mrichar1 / jsonapi-vuex

Use a JSONAPI api with a Vuex store, with data restructuring/normalization.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`toArray` function would be very handy

geoidesic opened this issue · comments

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);
        });

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.

That won't contain the id column, will it? But I guess I can get that via _jv property.