アプリケーションに更新機能を備えた非常に複雑なフォームがあり、ユーザーはいくつかのフィールドのみを変更して、[保存] ボタンをクリックしてデータをサーバーに送信できます。私のアプリケーションは、backbone、syphon、JQuery、および underscoreJs を使用しています。
アプリケーション内の複数のページで使用できるこれらのライブラリのみを使用して、サーバーに送信できるフィールドを制御する最良の方法は何ですか? 再利用可能な機能のようなものが役立ちます。
model.changedAttributes()
期待どおりに機能していないように見える機能を試しました。ほとんどの場合、false が返されます。次のコードでは、フォーム データが siphon を使用してシリアル化され、アプリ固有の形式に変換されて API に送信されます。
formSave: function(e) {
var data = changeToWriteApiFormat(Backbone.Syphon.serialize($(e.currentTarget).closest('form.event_form')[0]));
this.model.clear();
this.model.id = this.parentObj.model.id;
this.model.set(data);
if (this.model.isValid(true)) {
this.model.save(removeObjIndexCollection(data), {
url: this.model.url().replace(gc.readApiUrl, gc.publishApiUrl),
patch: true,
beforeSend: ToolsHelper.setPublishHeader,
success: function(model, response) {
$('#event_success').show();
$('#event_failure').hide();
},
error: function(model, response) {
$('#event_failure').show();
$('#event_success').hide();
}
}
}