I’m building a small app as a way of learning Fuse Tools and used the ‘News Feed’ exmample as a starting point.
My JSON (from an external API I have no control over) contains fixtures and results for football games.
All the finished games have the correct scores while game that haven’t been played yet have scores of -1, -1.
I don’t want to display a score if it’s value is -1, since is this isn’t a real score. So can I hide the node based on its value?
Is it better to parse the JSON response first creating Observables from everything I want to display. Or is there a way to change the stlye of a node depending on its value after I’ve displayed everything.
There are a lot of ways to do this, but I think the quickest way to do it if you want to get to the goal is to do JS manipulation of the data. Something like this does it:
I’d like to add +1 for the first answer; while both are valid (and great examples of both scenarios you describe), using observables in this way makes things much more readable and explicit
So, if your data is just an array of those fixtures, changing COCPORN’s original code to the following should work, given you “expand” the array into an Observable as shown:
// Fetch the data (an array of fixtures)
var originalData = fetch(...);
// Place the single array into an Observable
// Note that this Observable's value can be updated at any time
var observableData = new Observable(originalData);
// Project the array's contents into multiple values in another Observable (see https://www.fusetools.com/learn/fusejs#-expand-expand-func- )
var fixtures = observableData.expand();
var filteredFixtures = fixtures.where(function (fixture)
{
var result = fixture._links.result;
return !(result.score1 === -1 && result.score2 === -1);
});
Note that you don’t have to actually bind all these different Observables to variables; I only did that for clarity. Doing something like new Observable(...).expand().where(...) is perfectly fine
If i do it like that, i always get on accessing the panel it’s used in Unable to parse data: * (I’m not sure if it is a * at the end, but it looks like it)
It seems to work anyway, but as it tells me that something went wrong and it might affect the stability of the app somehow, i’d like to fix it. Any ideas what might cause this warning?
Yes, did test it with the 0.10 - still the same. Seems that i have to find another way to nest loops where the inner loop does use data from the outer loop.