Which is the best way to load confluence page comments with limit (incl. child-comments) by REST?
function load_comments(id, location, start, limit) { var rest_url = '/rest/api/content/' + id + '/child/comment?expand=body.view&location=' + location + '&start=' + start + '&limit=' + limit; $.ajax({ url: config.contextPath + rest_url, success: function(results) { if (results) { // if has childs .... recursive load_comments(...) } } }); }
Is it a good way to use nested ajax functions?
Community moderators have prevented the ability to post new answers.
I'm not sure this is the cleanest way to do it, but it works. It has two variables: limit and commentLimit. The "limit" variable sets the limit for the number of comments returned in a request. The "commentLimit" variable limits the total number of comments that are operated upon. Hopefully it will be helpful.
var commentCount = 0; function load_comments(id, location, start, limit, commentLimit) { var start = start || 0; var rest_url = '/rest/api/content/' + id + '/child/comment?expand=body.view,children.comment&start=' + start; if (location) { rest_url += '&location=' + location; } if (limit) { rest_url += '&limit=' + limit; } $.ajax({ url: contextPath + rest_url, success: function(response) { if (response.size) { $(response.results).each(function() { if (!commentLimit || commentLimit >= (commentCount += 1)) { console.log(this.body.view.value); if (this.children.comment.size) { load_comments(this.id, location, 0, limit, commentLimit); } } }); } if (response.size === response.limit) { load_comments(id, location, start += response.limit, limit, commentLimit); } } }); } load_comments(AJS.params.pageId, "", 0, 0, 5);
Thanks for your Anwser. Im so stupid ... depth=all Parameter is the Anwser for my Problem.
/rest/api/content/[PAGEID]/child/comment?expand=body.view&depth=all&limit=10
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
haha, nice! I learned something new today :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
But i dont find a parameter for the username... such as &expand=content. Any idea?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay i get it: ?expand=version
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
right, that should work. You can also expand both by putting a comma betwen them (i.e. ?expand=content,version Then you don't have to make duplicate requests :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.