Each with Observable problem

Back to How-to Discussions

Hello,

I am dealing with a problem and i have come to a dead end. I have a json file from which i read it and then write it to an Observable, later i add some more items to this Observable and also write them to the file. My problem is that i have a layout that i show each one of the items inside the Observable but if i add some items they don't show until i press Ctrl - R or close and reopen the Fuse emulator. This is the code i use to show the items :

<Panel Margin="0,10,0,20">
    <ColumnLayout ColumnSize="100" Sizing="Fill"/>
    <Each Items="{watch}">
        <watchlistCard Margin="5,5,5,5"/>
    </Each>
</Panel>

also the following code is to add a new item to the Observable:

genres.watchList.add(args.data);
FileSystem.writeTextToFileSync(FileSystem.dataDirectory +"/"+"watchlist.txt", JSON.stringify(genres.watchList));

If i put a button in the same layout as the Observable items and i print what the Observable has inside it prints what exactly should have, but it shows only the items that were imported from the start. It is like the each function doesn't refresh.

Hi!

It looks to me like you're not data-binding to the same observable as you're adding the items to:

The databinding is to watch while your "add" function adds to genres.watchList.

Could this be your problem?

Post Stats
  • 1
    replies
  • 432
    views
  • 2
    users