【问题标题】:How to reset X-editable fields after save event保存事件后如何重置 X 可编辑字段
【发布时间】:2014-01-23 18:20:33
【问题描述】:

这是https://stackoverflow.com/a/15121394/2247553 中此答案的后续问题,由于 StackOverflow 的奖励系统,我还不能对此发表评论。

我的问题是,在使用 Meteor 请求更新集合后,如果服务器拒绝更新,我如何将可编辑内容重置回其原始状态?

Template.editableTable.rendered = function() {

  $('#myParentTable').editable({
    selector: '.editable-click'
  });

  $('a.editable-click').unbind('save').on('save', function(e, params) {
    MyCollection.update({_id: 'myid'}, {$set: {key: 'val'}}, function(error, docs) {
      if (error) {
        // how do I reset X-editable here?
      }
    });
  });
};

【问题讨论】:

    标签: meteor x-editable


    【解决方案1】:

    根据FAQ,如果服务器端验证失败,你应该返回一个非200状态。

    我知道这并不能完全回答您的问题。我正在尝试做同样的事情,返回一个成功:假状态。它在某种程度上确实像一个 API,所以发回 200 表明一切正常,所以它会更新值。请求更新值,200状态表示成功。

    希望这是有道理的。如果您想澄清,请发表评论。 我的可编辑函数的错误参数代码如下...

    error: function(response, newValue) {
        var json = false;
        try {
            json = JSON.parse(response.responseText);
        } catch (e) {
            json = false;
        }
    
        //Bootstrap message is my own thing.
        bootstrapMessage.init('#search_results');
        if(response.status === 500) {
            bootstrapMessage.show_message('There is a server error. Please contact our supoprt team.', 'danger');
        } else {
            if(json){
                bootstrapMessage.show_message(json.message, 'danger');
            }else{
                bootstrapMessage.show_message('Problem saving your change. Please refresh the page and try again or contact our support team', 'danger');
            }
        }
    }
    

    【讨论】:

    • 我了解 200 代码,但是 Meteor 不支持以这种方式工作。您需要检查更新的结果回调才能判断是否有错误。最初的更新调用本身将始终按设计成功(使用 Meteor 时)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-16
    • 1970-01-01
    • 2018-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多