# How refresh the ViewModel Data?

**URL:** <https://forums.bitovi.com/t/how-refresh-the-viewmodel-data/256>\
**Category:** CanJS\
**Created:** [May 6, 2016, 8:14pm UTC](https://forums.bitovi.com/t/how-refresh-the-viewmodel-data/256 "2016-05-06T20:14:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maj0rrush](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/maj0rrush/32/117_2.png) [@Maj0rrush](https://forums.bitovi.com/u/Maj0rrush)\
**Post date:** [May 6, 2016, 8:14pm UTC](https://forums.bitovi.com/t/how-refresh-the-viewmodel-data/256/1 "2016-05-06T20:14:36Z")

</div>

Is there any Refresh Method to refresh ViewModel Data ??

http://jsbin.com/jepiyu/1/embed?html,js,output

---

<div class="post-metadata">

**Author:** ![DylanRoss](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/dylanross/32/71_2.png) [@DylanRoss](https://forums.bitovi.com/u/DylanRoss)\
**Post date:** [May 6, 2016, 8:47pm UTC](https://forums.bitovi.com/t/how-refresh-the-viewmodel-data/256/2 "2016-05-06T20:47:23Z")

</div>

The easiest way is to leverage the model store by calling `Portal.findAll({})` again. If you have setup the model correctly (‘id’ property), instances will be updated automatically through the store when the promise resolves. If the resulting list has a different number of results, however, I don’t believe can.Model handles this well, so can-connect has diffing logic for that case if you want to give it a try.

If you aren’t using can-connect and you need list diffing, here’s a semi-hacky trick where you create a dummy field as a dependency and then trigger it to cause a recompute.

```auto
define: {
  portals: {
    get: function(lastSetValue, resolve) {
      // recompute on 'refreshPortals' event
      this.attr('refreshPortals');
      Portals.findAll({}).then(resolve);
    }
  }
},
refreshData: function() {
  can.trigger(this, 'refreshPortals');
}

```

---

<div class="post-metadata">

**Author:** ![Maj0rrush](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/maj0rrush/32/117_2.png) [@Maj0rrush](https://forums.bitovi.com/u/Maj0rrush)\
**Post date:** [May 7, 2016, 7:37pm UTC](https://forums.bitovi.com/t/how-refresh-the-viewmodel-data/256/3 "2016-05-07T19:37:41Z")

</div>

Hi,

thank you. refreshing now is working.

But why is my portals.isPending not working ?

http://jsbin.com/jepiyu/embed?html,js,output

---

<div class="post-metadata">

**Author:** ![DylanRoss](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/dylanross/32/71_2.png) [@DylanRoss](https://forums.bitovi.com/u/DylanRoss)\
**Post date:** [May 7, 2016, 7:51pm UTC](https://forums.bitovi.com/t/how-refresh-the-viewmodel-data/256/4 "2016-05-07T19:51:24Z")

</div>

That’s because `portals` is just a compute, not a promise. Instead, you could simply wait on `portals` in the template. Some people don’t like that style but it gets the job done.

---

<div class="post-metadata">

**Author:** ![Maj0rrush](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/maj0rrush/32/117_2.png) [@Maj0rrush](https://forums.bitovi.com/u/Maj0rrush)\
**Post date:** [May 7, 2016, 8:21pm UTC](https://forums.bitovi.com/t/how-refresh-the-viewmodel-data/256/5 "2016-05-07T20:21:17Z")

</div>

Hi for anyone else, i tried a approach from Dylan from another Post and this works …

http://jsbin.com/jepiyu/embed?html,js,output
