2

这是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?
      }
    });
  });
};
4

1 回答 1

0

根据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');
        }
    }
}
于 2014-02-13T15:05:53.423 回答