简体   繁体   English

在确定单击时将 VueDraggable model 数据传回 b-modal

[英]Passing VueDraggable model data back to b-modal on OK click

We've got the following template structure:我们有以下模板结构:

        <b-modal
          id="reorder-modal"
          title="Reorder Dashboard"
          @ok="storeNewOrder"
          ok-title="Save"
          ok-variant="success"
          :ok-disabled="disableSave">
            <reorder-modal-row
              :dash-board-data="dashBoardData"
              :disable-save="disableSave"
              @updateDisableSave="updateDisableSave"/>
        </b-modal>

reorder-modal-row is essentially a draggable component like so: reorder-modal-row本质上是一个可拖动的组件,如下所示:

  <div>
    <draggable-component
      v-model="dashBoardDataClone"
      :move="updatePosition"
      handle=".handle"
      ghost-class="ghost"
      @start="drag=true"
      @end="drag=false">
      <div
        v-for="card in dashBoardDataClone"
        :key="card.id"
        class="card-list-item border p-2 my-3">
          <font-awesome-icon icon="align-justify" class="handle"/>
          {{card.db_name}}
      </div>
    </draggable-component>
  </div>

Now, the model of the draggable component uses a clone of the data passed via props :dash-board-data .现在,可拖动组件的 model 使用通过 props 传递的数据的克隆:dash-board-data What we're trying to achieve is that when the user clicks on the Save button inside the b-modal that should collect the cloned data from the child and make a back-end call to update or database.我们想要实现的是,当用户单击b-modal内的 Save 按钮时,它应该从子级收集克隆的数据并进行后端调用以更新或数据库。 The problem is that we are not sure how to achieve this functionality since the Save button is not part of the child.问题是我们不确定如何实现此功能,因为 Save 按钮不是子项的一部分。

We tried using the draggable move event but that emits an event to the parent on every drag.我们尝试使用可拖动的移动事件,但每次拖动都会向父级发出一个事件。 Any help will be appreciated !任何帮助将不胜感激 !

The solution we found was to create a copy of the data.我们找到的解决方案是创建数据的副本。 2-way bind that with the child and on Save button click we assign the original data to the copy. 2-way 将它与孩子绑定,然后单击Save按钮,我们将原始数据分配给副本。

methods: {
  async loadGridAndContent () {
    let result = await AppService.loadDashboard(this.userDetails.psref)
    this.dashBoardData = result.data[0]
    this.dashBoardDataClone = JSON.parse(JSON.stringify(this.dashBoardData))
  },
  async storeNewOrder () {
    this.dashBoardData = this.dashBoardDataClone
    await AppService.reorderDashboard(this.dashBoardData)
  },
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM