admin管理员组文章数量:1291089
In the save method of the Model chapter, Backbone.js documentation says:
If instead, you'd only like the changed attributes to be sent to the server, call model.save(attrs, {patch: true}). You'll get an HTTP PATCH request to the server with just the passed-in attributes.
Source:
I could not find a good explanation of the way this actually works (and if it actually works!). It should send a PATCH request to the server with just the passed-in attributes, but it always sends a POST request to the server will ALL the attributes of the model. And with Firebug, I cannot see any difference when changing Backbone.emulateHTTP
: Firebug always shows POST requests with the save method.
I created a test here: / Note that the url does not exist of course, but the important is to see the POST request in Firebug. As you can see, if you try to send only one attribute, it will always send everything to the server, making the option totally useless.
Why Backbone developers offer this options and what is it for? Could you show an example of its use?
In the save method of the Model chapter, Backbone.js documentation says:
If instead, you'd only like the changed attributes to be sent to the server, call model.save(attrs, {patch: true}). You'll get an HTTP PATCH request to the server with just the passed-in attributes.
Source: http://backbonejs/#Model-save
I could not find a good explanation of the way this actually works (and if it actually works!). It should send a PATCH request to the server with just the passed-in attributes, but it always sends a POST request to the server will ALL the attributes of the model. And with Firebug, I cannot see any difference when changing Backbone.emulateHTTP
: Firebug always shows POST requests with the save method.
I created a test here: http://jsfiddle/r9kXL/ Note that the url does not exist of course, but the important is to see the POST request in Firebug. As you can see, if you try to send only one attribute, it will always send everything to the server, making the option totally useless.
Why Backbone developers offer this options and what is it for? Could you show an example of its use?
Share Improve this question edited Mar 24, 2014 at 17:55 morten.c 3,5155 gold badges42 silver badges47 bronze badges asked Jun 28, 2013 at 17:48 taseenbtaseenb 1,4431 gold badge17 silver badges31 bronze badges 1-
When I read about the
{ patch: true }
option in the docs and try to figure out how it works, I ask myself how to determine which attributes I have to pass in order to send only the unsaved attributes to the server. If someone else want to now, you could read this related answer of mine. Hopes this helps someone. – morten.c Commented Mar 23, 2014 at 17:23
1 Answer
Reset to default 11This happens because your model isNew
and Backbone "creates new instance" (method create
) instead of patching existing one (method patch
). Take a look - http://jsfiddle/r9kXL/1/
'create': 'POST',
'update': 'PUT',
'patch': 'PATCH',
'delete': 'DELETE',
'read': 'GET'
本文标签: javascriptHow to use Backbonejs partial update (patch true)Stack Overflow
版权声明:本文标题:javascript - How to use Backbone.js partial update (patch: true)? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741502747a2382141.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论