# Endless Scrollable News

**URL:** <https://forums.fusetools.com/t/endless-scrollable-news/5470>\
**Category:** General\
**Created:** [May 25, 2017, 2:57pm UTC](https://forums.fusetools.com/t/endless-scrollable-news/5470 "2017-05-25T14:57:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dsbilling](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/dsbilling/32/723_2.png) [@dsbilling](https://forums.fusetools.com/u/dsbilling)\
**Post date:** [May 25, 2017, 2:57pm UTC](https://forums.fusetools.com/t/endless-scrollable-news/5470/1 "2017-05-25T14:57:14Z")

</div>

I can’t get this to work. Am I using the Observable add-function wrong? I want to add X news when the scroll reaches the end, but it seems like it is not.

JavaScript:

```auto
<JavaScript>
    var Observable = require("FuseJS/Observable");
    var data = new Observable();
    var skip = 0;

    function addNews() {
        fetch('https://example.com/api/news/' + 5 + '/' + skip)
        .then(function(response) { return response.json(); })
        .then(function(responseObject) { data.add(responseObject); });
        skip = skip + 5;
    }

    addNews();

    module.exports = {
        data: data,
        addNews: addNews
    };
</JavaScript>

```

The view:

```auto
<ScrollView ux:Name="mainScrollView" ClipToBounds="false" LayoutMode="PreserveVisual">
    <StackPanel Margin="0,0,0,15">
        <Selection MinCount="0" MaxCount="1" />
        
        <Each Items="{data.entries}">
            <Deferred>
                <EventCard layoutTarget="contentPlaceholder">
                    <Selectable Value="{id}" />
                </EventCard>
            </Deferred>
        </Each>
    </StackPanel>
    <Scrolled To="End" Within="100" Handler="{addNews}" />
</ScrollView>

```

---

<div class="post-metadata">

**Author:** ![felagund18](https://avatars.discourse-cdn.com/v4/letter/f/7cd45c/32.png) [@felagund18](https://forums.fusetools.com/u/felagund18)\
**Post date:** [May 25, 2017, 3:44pm UTC](https://forums.fusetools.com/t/endless-scrollable-news/5470/2 "2017-05-25T15:44:22Z")

</div>

make it

```auto
   function addNews() {
        fetch('https://example.com/api/news/' + 5 + '/' + skip)
        .then(function(response) { return response.json(); })
        .then(function(responseObject) { 
            skip = skip + 5;
            data.add(responseObject); 
        });
   }

```

---

<div class="post-metadata">

**Author:** ![dsbilling](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/dsbilling/32/723_2.png) [@dsbilling](https://forums.fusetools.com/u/dsbilling)\
**Post date:** [May 25, 2017, 3:53pm UTC](https://forums.fusetools.com/t/endless-scrollable-news/5470/3 "2017-05-25T15:53:49Z")

</div>

> **[felagund18@yahoo.com](mailto:felagund18@yahoo.com) wrote:**
> 
> make it
> 
> ```auto
> function addNews() {
> fetch('https://example.com/api/news/' + 5 + '/' + skip)
> .then(function(response) { return response.json(); })
> .then(function(responseObject) { 
> skip = skip + 5;
> data.add(responseObject); 
> });
> }
> 
> ```

Thanks! But it did not work, it does not append the new news to the data/does not show.

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [May 25, 2017, 4:00pm UTC](https://forums.fusetools.com/t/endless-scrollable-news/5470/4 "2017-05-25T16:00:07Z")

</div>

If the `responseObject` is an array, you will want to use `.addAll()` instead of `.add()`.

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [May 25, 2017, 4:15pm UTC](https://forums.fusetools.com/t/endless-scrollable-news/5470/5 "2017-05-25T16:15:14Z")

</div>

On a second look, you are trying to loop through a nested property on an observable, like so: `<Each Items="{data.entries}">`. That won’t work.

Your `data` wants to be a _list_. And you want to feed it an _array_, using the correct methods.

You will want to change the UX to:

```auto
<Each Items="{data}">

```

and the JS to:

```auto
   function addNews() {
        fetch('https://example.com/api/news/' + 5 + '/' + skip)
        .then(function(response) { return response.json(); })
        .then(function(responseObject) { 
            skip = skip + 5;
            data.addAll(responseObject.entries); 
        });
   }

```

But all this is highly speculative, since there is zero visibility on what the data structures you are working with look like. And you clearly should go and spend some time on [this page on Observables](https://www.fusetools.com/docs/fusejs/observable).

---

<div class="post-metadata">

**Author:** ![dsbilling](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/dsbilling/32/723_2.png) [@dsbilling](https://forums.fusetools.com/u/dsbilling)\
**Post date:** [May 25, 2017, 5:42pm UTC](https://forums.fusetools.com/t/endless-scrollable-news/5470/6 "2017-05-25T17:42:16Z")

</div>

> **Uldis wrote:**
> 
> On a second look, you are trying to loop through a nested property on an observable, like so: `<Each Items="{data.entries}">`. That won’t work.
> 
> Your `data` wants to be a _list_. And you want to feed it an _array_, using the correct methods.
> 
> You will want to change the UX to:
> 
> ```auto
> <Each Items="{data}">
> 
> ```
> 
> and the JS to:
> 
> ```auto
> function addNews() {
> fetch('https://example.com/api/news/' + 5 + '/' + skip)
> .then(function(response) { return response.json(); })
> .then(function(responseObject) { 
> skip = skip + 5;
> data.addAll(responseObject.entries); 
> });
> }
> 
> ```
> 
> But all this is highly speculative, since there is zero visibility on what the data structures you are working with look like. And you clearly should go and spend some time on [this page on Observables](https://www.fusetools.com/docs/fusejs/observable).

Thank you! I understand it now 🙂
