My data model is look like the following JSON structure (just example):
var post = {
id: 123,
title: 'Sterling Archer',
comments: [
{text: 'Comment text', tags: ['tag1', 'tag2', 'tag3']},
{text: 'Comment test', tags: ['tag2', 'tag5']}
]
};
In Backbone side it represented as nested model that looks likes the following:
var PostModel = Backbone.Model.extend({
parse: function (response) {
if (response.comments) {
response.comments = new Backbone.Collection(response.comments);
}
return response;
}
});
var post = new PostModel(post, {parse: true});
I want to apply rfc6902 (JSONPatch) specification to my structure. But the problem here is that my structure is not pure JSON but nested model/collection units.
I need best practices about how could I patch my nested backbonejs structure like in official documentation examples:
Does anybody has experience in using JSON+Patch specification in your BackboneJS applications? Please share with us.
Thanks.
EDIT: here is the short example. Let's say I need to make some modifications on my post model like comment adding:
var op = [
{ "op": "add", "path": "/comments/2", "value": {text: 'Comment test3', tags: ['tag4']}" }
]
How could I do it with backbone:
post.appyPatch(op);
Is there any best practices or/and backbone extensions for do it?
async
method inBackbone
does not support this type of request unfortunately. You could always extend it yourself. That would be thebest practice
IMHO. You could always look at this JSON patch library and get some cues.