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 以外のステータスを返す必要があります。

これがあなたの質問に正確に答えていないことは知っています。私は同じことをしようとしています.success:falseステータスを返します. ある意味で 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 に答える