Currently developing a vue
-application that includes a component for managing driving licenses.
Here is an overview of my data setup:
data() {
return {
custom_licenses: [],
basic_licenses: []
}
}
Within my methods, I have the following logic:
regular_licenses() {
this.$store.dispatch("license/read").then(response => {
response.licenses.map((license, key) => {
// PUSH LICENSES WITH TYPE 'BASIC' TO this.basic_licenses
// PUSH LICENSES WITH TYPE 'CUSTOM' TO this.custom_licenses
});
});
},
In the creation stage (created()
), the method this.regular_licenses()
is called.
The result obtained from the dispatch call looks like this:
licenses:
[
{
id: 1,
type: 'basic',
name: 'AMa'
},
{
id: 2,
type: 'basic',
name: 'A2'
},
{
id: 3,
type: 'basic',
name: 'C'
},
{
id: 4,
type: 'custom',
name: 'C1'
},
{
id: 5,
type: 'custom',
name: 'D'
},
and so on...
]
Now, the goal is to iterate through the array and appropriately categorize them into custom_licenses
and basic_licenses
based on the type
attribute - any suggestions on how to tackle this task?