简体   繁体   English

合并Javascript中的对象以无限加载Ajax插件

[英]Merging Objects in Javascript for Infinite Loading Ajax Plugin

I am trying to implement infinite scrolling. 我正在尝试实现无限滚动。 An ajax request returns an object that includes 10 threads. 一个ajax请求返回一个包含10个线程的对象。 This ajax request is called every time the user scrolls to the bottom. 每当用户滚动到底部时,都会调用此ajax请求。 What I am looking for is a way to merge these objects together. 我正在寻找一种将这些对象合并在一起的方法。

One object looks like this: 一个对象看起来像这样:

Article: Object
    page: 1
    last_page: 20
    data: Array[10]
        0: Object
        1: Object
        2: Object

Inside of the data array objects are arrays and objects again... So my problem here really is that we're speaking of a quite large object containing a variety of objects and arrays. 在数据数组内部,对象又是数组和对象……所以,我的真正问题是,我们所说的是一个包含各种对象和数组的相当大的对象。 Any idea how I could manage to do this? 知道我如何能够做到这一点吗?

Thank you! 谢谢! <3 <3

To add an array to another you could use the following code: 要将数组添加到另一个数组,可以使用以下代码:

// `b` onto `a`:
a.push.apply( a, b );

More information on the best way of merging/combining arrays may be found at this link . 有关合并/合并数组的最佳方法的更多信息,请参见此链接

In your case it would seem you keep one big pile of data (in the end). 就您而言,似乎您保留了一大堆数据(最后)。 That would mean you would push the new article data on top of the pile. 这意味着您将把新文章数据推到最前面。 Since you know that this pile will be the biggest, it would give a good performance if you used this: 由于您知道该堆将是最大的,因此,如果使用以下命令,它将获得良好的性能:

var articlePile = article.data;
// For every new article push the data onto the pile
articlePile.push.apply( articlePile, article2.data );

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

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