0

所以,我正在使用 Sailsjs - 我正在使用模态表单来确认删除项目。我想要做的是检测双重删除(有人删除了一个项目 - 当它在别人的页面中时 - 第二个人也试图删除它)。我设法做到了——我的行动是返回“notFound”。问题是 - 当从操作中获取“notFound”而不是成功时,如何使模态关闭?

这是我的操作代码的摘录:

  exits: {

    forbidden: {
      description: 'The user making this request is not the owner of this thing and therefore cannot delete it.',
      responseType: 'forbidden'
    },

    notFound: {
      description: 'The item was not found in the database. Maybe it has already been deleted?',
      responseType: 'notFound'
    }

  },


  fn: async function (inputs, exits) {

    var thing = await Thing.findOne({
      id: inputs.id
    });

    if (!thing) {
      throw 'notFound';
    }

    if (thing) {
      if (thing.owner !== this.req.me.id ) {
        throw 'forbidden';
      }
    }

    await Thing.destroy({ id: inputs.id });

    return exits.success();

  }

这是我使用 ajax-form 组件的模态的摘录:

  <% /* Confirm DeleteThing Modal */%>
  <modal v-if="confirmDeleteThingModalOpen" @close="closeDeleteThingModal()">
    <ajax-form action="destroyOneThing" :syncing.sync="syncing" :cloud-error.sync="cloudError" :handle-parsing.sync="handleParsingDeleteThingForm" @submitted="submittedDeleteThingForm()">
      <div class="modal-header">
        <h3 class="modal-title">Are you sure?</h3>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>

4

1 回答 1

0

您可以在 ajax 表单上使用 @rejected。所以类似:

<ajax-form action="destroyOneThing" @rejected="rejectedDeleteOneThing" 

然后告诉它你想让它在你的页面脚本上做什么

就像是:

    rejectedDeleteOneThing: function() {
      this.confirmDeleteThingModalVisible = false;
    }
于 2018-08-20T19:46:23.787 回答