【问题标题】:Ag-grid - Events and Methods (Vuejs)Ag-grid - 事件和方法 (Vuejs)
【发布时间】:2020-03-08 11:22:02
【问题描述】:

我无法使用“保存”方法来保存对表格数据的更改

我正在使用“cellValueChanged”方法来编辑和保存表格单元格。

<ag-grid-vue :cellValueChanged="save"></ag-grid-vue>

methods: {
    save() {
        const method = this.instituicao.id ? 'put' : 'post'
        const id = this.instituicao.id ? `/${this.instituicao.id}` : ''
        axios[method](`${baseApiUrl}/instituicao${id}`, this.instituicao)
            .then(() => {
                this.$toasted.global.defaultSuccess()
                this.reset()
            })
            .catch(showError)
},

错误信息: enter image description here

【问题讨论】:

  • 你试过this.instituicao的console.log吗,似乎是未定义的
  • 是的,我可以查看机构数据:mounted() { this.columnDefs = [ {headerName: 'ID', field: 'id', filter: false, editable: true}, { headerName:'Código do Banco',字段:'codigo',过滤器:false,可编辑:true},{headerName:'Nome do Banco',字段:'nome',过滤器:false,可编辑:true}]; axios.get(${baseApiUrl}/instituicao) .then(({data}) => this.rowData = data) },
  • 尝试使用 this.instituicao & instituicao.id
  • 哪一行代码?
  • const 方法 = this.instituicao & instituicao.id? “放”:“发布”

标签: vue.js events ag-grid


【解决方案1】:

为了达到预期的效果,使用@cell-value-changed的事件回调

  1. 将您的事件更改为@cell-value-changed = "save"
  2. 使用事件回调获取单元格的新旧值

save(event) { console.log('onCellValueChanged: ' + event.oldValue + ' to ' + event.newValue); }

  1. 从该事件回调中获取所需的 id 值并将其用于 POST 调用

【讨论】:

  • 我能够通过请求参数使用 axios 应用 POST 方法: axios [method] ($ {baseApiUrl} / institution / $ {event.data.id}, event.data) 如何在多行上应用方法?
猜你喜欢
  • 2019-06-06
  • 2020-04-21
  • 2017-12-12
  • 1970-01-01
  • 2021-04-17
  • 2021-11-12
  • 2019-04-06
  • 2018-01-16
  • 2020-01-23
相关资源
最近更新 更多