开发者

Backbone Model.save doesn't wrap model state to nested object

开发者 https://www.devze.com 2023-03-07 00:49 出处:网络
Backbone Model.save doesn\'t wrap model state to nested object. Is it normal开发者_C百科? Typical scenario for Rails is something like this params[:product]. How could I achieve this?This was answere

Backbone Model.save doesn't wrap model state to nested object. Is it normal开发者_C百科?

Typical scenario for Rails is something like this params[:product]. How could I achieve this?


This was answered previously: Saving nested objects with Rails, backbone.js, and accepts_nested_attributes_for

I would suggest to override toJSON on the backbone model.

toJSON: function(){

  json = {car : this.attributes};
  return _.extend(json, {engine_attributes: this.get("engine").toJSON());

}

toJSON is called within the sync method just before sending data to the backend.

0

精彩评论

暂无评论...
验证码 换一张
取 消