# Refreshing Each block

**URL:** <https://forums.fusetools.com/t/refreshing-each-block/5988>\
**Category:** How-to Discussions\
**Created:** [February 2, 2016, 4:44pm UTC](https://forums.fusetools.com/t/refreshing-each-block/5988 "2016-02-02T16:44:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gdeichen](https://avatars.discourse-cdn.com/v4/letter/g/35a633/32.png) [@gdeichen](https://forums.fusetools.com/u/gdeichen)\
**Post date:** [February 2, 2016, 4:44pm UTC](https://forums.fusetools.com/t/refreshing-each-block/5988/1 "2016-02-02T16:44:23Z")

</div>

Hiya,

If I have created an Each block from data, is it possible to make it update with new data? I.e. to redraw all of the elements that it contains with their new values?

Thanks…!

---

<div class="post-metadata">

**Author:** ![Kristian\_Hasselknipp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/kristian_hasselknipp/32/549_2.png) [@Kristian\_Hasselknipp](https://forums.fusetools.com/u/Kristian_Hasselknipp)\
**Post date:** [February 2, 2016, 5:03pm UTC](https://forums.fusetools.com/t/refreshing-each-block/5988/2 "2016-02-02T17:03:49Z")

</div>

Hi!

That should happen automatically if you’re using `Observables`. What does you code look like?

---

<div class="post-metadata">

**Author:** ![gdeichen](https://avatars.discourse-cdn.com/v4/letter/g/35a633/32.png) [@gdeichen](https://forums.fusetools.com/u/gdeichen)\
**Post date:** [February 2, 2016, 5:54pm UTC](https://forums.fusetools.com/t/refreshing-each-block/5988/3 "2016-02-02T17:54:21Z")

</div>

That would make sense; the problem I’m having is getting an Observable to work directly with an Each block;

This works:

```auto
<JavaScript>
var Observable = require("FuseJS/Observable");

var answerText = Observable("");
var currentQuestion = 0;

updateAnswers = function()
{
    answerText.value = questions[currentQuestion].answers;
}

getAnswers = function()
{
    return answerText.value;
}

updateAnswers();

module.exports = {
    getAnswers: getAnswers(),
    answerText: answerText
}

</JavaScript>

<Each Items="{getAnswers}">
<Text Font="typewr" FontSize="60" Alignment="Center" Value="{answer}" Padding="5,3" TextWrapping="Wrap" />
...
</Each>

```

Whereas if I replace the Each block with this, it does not:

```auto
<Each Items="{answerText}">
<Text Font="typewr" FontSize="60" Alignment="Center" Value="{answer}" Padding="5,3" TextWrapping="Wrap" />
...
</Each>

```

The data is sourced from a (pseudo) JSON file and it works perfectly with the getAnswers abstraction.

---

<div class="post-metadata">

**Author:** ![gdeichen](https://avatars.discourse-cdn.com/v4/letter/g/35a633/32.png) [@gdeichen](https://forums.fusetools.com/u/gdeichen)\
**Post date:** [February 2, 2016, 7:24pm UTC](https://forums.fusetools.com/t/refreshing-each-block/5988/4 "2016-02-02T19:24:55Z")

</div>

Interesting… if I create the answerText Observable with the values from the JSON, it works:

```auto
            var answerText = Observable(
                {"answer":"1901"},
                {"answer":"c. 150"},
                {"answer":"1940"},
                {"answer":"1840", "correct":"true"},
                {"answer":"1801"} );

```

As it appears in the JSON file:

```auto
module.exports = [
        {
            "question":"In what year...",
            "answers":[
                {"answer":"1901"},
                {"answer":"c. 150"},
                {"answer":"1940"},
                {"answer":"1840", "correct":"true"},
                {"answer":"1801"}
            ]
        }
];

```

Perhaps I need to manipulate the JSON on the way into the Observable?

---

<div class="post-metadata">

**Author:** ![gdeichen](https://avatars.discourse-cdn.com/v4/letter/g/35a633/32.png) [@gdeichen](https://forums.fusetools.com/u/gdeichen)\
**Post date:** [February 2, 2016, 7:35pm UTC](https://forums.fusetools.com/t/refreshing-each-block/5988/5 "2016-02-02T19:35:58Z")

</div>

Right, got it…

.value is only for adding single values to an Observable, so what I needed was an array function. Thus my updateAnswers function should look like this:

```auto
  updateAnswers = function()
  {
      answerText.replaceAll(questions[currentQuestion].answers);
  }

```

That grabs the array of answers to the specified question from the JSON and adds it to the Observable in place of any existing value(s).

Thanks for the prod in the right direction 🙂

---

<div class="post-metadata">

**Author:** ![Carla\_Andia](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/carla_andia/32/340_2.png) [@Carla\_Andia](https://forums.fusetools.com/u/Carla_Andia)\
**Post date:** [April 29, 2016, 3:38pm UTC](https://forums.fusetools.com/t/refreshing-each-block/5988/6 "2016-04-29T15:38:42Z")

</div>

I was fighting with the same thing all day and that “replaceAll” make my day, so I have to say thank you!!
