[Vuejs]-Adding a headline only if none is set already

0👍

You did not provide your full code, so I don’t know how your Objects look like.

One possible solution could be grouping your items by date in a Vue Computed function.

const groupBy = key => array =>
  array.reduce((objectsByKeyValue, obj) => {
    const value = obj[key];
    objectsByKeyValue[value] = (objectsByKeyValue[value] || []).concat(obj);
    return objectsByKeyValue;
  }, {});

const items = [
  { name: 'XY', date: '01.02.2019' },
  { name: 'DEF', date: '05.03.2019' },
  { name: 'ABC', date: '05.03.2019' },
  { name: 'FOO', date: '05.03.2019' }
];

const groupByDate = groupBy('date');

console.log(
  JSON.stringify(groupByDate(items), null, 2)
);

Add this code to a computed Vue Function:
Vue computed documentation

Leave a comment