A
A
asferot2019-02-20 10:56:59
Vue.js
asferot, 2019-02-20 10:56:59

How to redefine the name coming from the database?

The question is. A table with projects from the database comes in, there are contractors, and so on. Contractors come in the form of id, and the names themselves are stored in another table. I need to display titles, not id. How can this be implemented?
The table with projects, for example, is called data_42, the field with partners is f8260 and this field displays id from the table with partners (1610, 1850, etc.), and the table with partners data_420 and, accordingly, the id field matches f8260 from the table with projects , and the field f435 stores the names of agents.
How do I get data from tables:

loadProject ({commit}) {
            var CancelToken = axios.CancelToken
            var source = CancelToken.source()
            axios.post('/project', {
              _csrf: document.querySelector('meta[name="csrf-token"]').getAttribute('content')
            })
                .then(data => data.data)
                .then(projects => {
                    commit('get_projects', projects)
            })
        },

actions: {
loadCounteragents ({commit}) {
            var CancelToken = axios.CancelToken
            var source = CancelToken.source()
            axios.post('/counteragents', {
              _csrf: document.querySelector('meta[name="csrf-token"]').getAttribute('content')
            })
                .then(data => data.data)
                .then(counteragents => {
                    commit('get_counteragents', counteragents)
            })
        }
}

getters: {
filterProjects(state) {
            return state.projects.filter(project => {
                return project
            })
        },
        filterProjectsF8260(state) {
            return state.projects.map(project => {
                return project.f8260
            })
        },
        filterAgnetId(state) {
            return state.counteragents.map(counteragent => {
                return counteragent.id
            })
        },
        filterAgnetName(state) {
            return state.counteragents.map(counteragent => {
                return counteragent.f435
            })
        },
        filterCounteragents(state) {
            return state.counteragents.filter(counteragent => {
                return counteragent
            })
        }
}

I hope the question is clear, if you need something else, ask

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Malyarov, 2019-02-20
@Konstantin18ko

https://ru.vuejs.org/v2/guide/filters.html
Through filters.
Send an id to the filter, issue a query in it, and return a string.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question