I would put the elements of response.result.results into the collection this way:
parse: function(response) {
if (response.status == 'ok') {
this.page = response.result.page;
this.count = response.result.count;
this.total = response.result.total;
this.sort = response.result.sort;
this.ascending = response.result.ascending;
return response.result.results;
} else {
}
}
Now if fetching the collection succeeds, and response.status is 'ok', then:
- your collection will have fields called
page, count, total, sort and ascending,
- these fields will contain the values you get as the fields of
response.result,
- the
length of the collection will be the length of response.result.results, and
- the items of the collection will be the items of
response.result.results, so you can iterate over them inside the success handler of fetch.
If the fetch fails, or response.status is not 'ok', then the length of the collection will be zero. The fields page, count, total, sort and ascending will be undefined, unless you define them somewhere, for example in initialize or in the else branch inside the above parse function.
Here is a working example. The output is printed in the console, so e.g. in Chrome, press F12 and change to the Console tab. Anyway, since Backbone collections have a method called sort, I would change the name of the sort field to something else (sorted, toBeSorted, etc. - I don't know the semantics of this field).