简体   繁体   中英

Having trouble logically setting up a page system for Backbone

So I am getting a response from the server with the following array

[
   [{title: "abc", author: "james"}, {title: "bcd", author: "jack"}],
   [{title: "cde", author: "john"}, {title: "def", author: "jake"}], 
   [{title: "xyz", author: "frank"}]
]

Now with Backbone I am trying to take this response and create pages, 1 for each sub-array and then on each page it should show the info within each sub-array.

I was using request.js to define and separate the files, and this is my take on the models, views, and collections but for some reason I cannot understand what is the right approach because the information comes back in a collection.

I was going to create a view for each sub-array's object. so for the objects I will display a

<td> "abc" </td>
<td> "james" </td>

that would be in a collection with a fetch calling the data then looping through each data and showing the amount of objects per page (2 in this example)

then writing a function that if the next page === 1 then print out the second sub-array, etc...

then similarly a view for the pages with the same concept, depending on the route:pageid show each page with a next and prev button that takes you to current -1 or current +1 of the pageid... but In the way I am visioning this I do not see a place for a model... does that make sense or if there is a better way to do all this with the response from the server please share.

Thank you

Backbone.Collection is tied to the Array concept. It is meant to be an array of objects, not an array of arrays of objects. Your problem will be better solved by using a single collection (that would abstract the data more cleanly) and pagination.

See this question for further directions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM