简体   繁体   English

在逻辑上为Backbone设置页面系统时遇到麻烦

[英]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. 现在,使用Backbone,我尝试采取此响应并创建页面,每个子阵列1个,然后在每个页面上它应显示每个子阵列中的信息。

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. 我当时使用request.js定义和分离文件,这是我对模型,视图和集合的看法,但是由于某些原因,我无法理解什么是正确的方法,因为信息返回了集合。

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) 将会在一个集合中进行提取,该调用将调用数据,然后遍历每个数据并显示每页的对象数量(此示例中为2)

then writing a function that if the next page === 1 then print out the second sub-array, etc... 然后编写一个函数,如果下一页=== 1,则打印出第二个子数组,依此类推...

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. 然后类似地查看具有相同概念的页面的视图,具体取决于路线:pageid显示每个页面的下一个和上一个按钮,可将您带到当前的pageid -1或当前+1 ...但是,按照我的方式看到这一点,我看不到模型的位置...这是否有意义,或者如果有更好的方法来处理服务器的响应,请分享。

Thank you 谢谢

Backbone.Collection is tied to the Array concept. Backbone.CollectionArray概念相关。 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. 有关更多说明,请参见此问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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