A
A
asd dsa2019-10-01 20:29:43
JavaScript
asd dsa, 2019-10-01 20:29:43

How to add name to multiple entities with store?

I want to add the name of each entity through its id, but I don’t get the name, please help me solve the problem
Here I monitor the metrics that change and if the condition works, I pass the metric objects with the metric id key and the value of its name in store mutations

watch: {
        metric() {
            if (this.metric) {
                this.setSingleMetricNamesMap({ [this.metric.id]: this.metric.name })
            }
        }
    },

state
I understand that primitive types are preferable for vuex, I tried to set the value to null, but then several objects (metrics) are not added to the state state getter , I try to return the name of the metric for the identifier, instead of an object containing the names and identifiers of the metric.
singleMetricNamesMap: []
singleMetricNamesMap: state => state.singleMetricNamesMap

state mutations
Write metric objects to state
setSingleMetricNamesMap: (state, val) => {
            state.singleMetricNamesMap.push(val)
        },

The component where I call the state getter and try to get the names of the metrics by their Id
showNames() {
            return this.singleMetricNamesMap.forEach(el => el[this.value.metricId])
        }

<z-dash-tile-config-option
            label="Metric"
            :value="showNames"  // здесь  делаю bind  имен  для метриков
        >

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-10-02
@yaNastia

return this.singleMetricNamesMap.forEach(el => el[this.value.metricId])

Cool.
Open the documentation, understand what forEach is. And what other methods do arrays have.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question