Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>OK, so after much fiddling about I've made some progress. Sorry Ward (if you read this) - your documentation may be great for experienced coders but it's not good for noobs!)</p> <p>Top of dataservice.js is now this:</p> <pre><code>var manager = new breeze.EntityManager(serviceName); var store = manager.metadataStore; var Game = function () { //this.result = "Won 3-2"; }; var gameInitializer = function (game) { //game.result = "Won 3-2"; game.result = function () { return getResult(game); }(); }; store.registerEntityTypeCtor("Game", Game, gameInitializer); </code></pre> <p>and the getResult function:</p> <pre><code>function getResult(game) { var ourSets = 0; var theirSets = 0; game.Sets().forEach(function (gs) { if (gs.ourScore() &gt; gs.theirScore()) { ourSets += 1; } else { theirSets += 1; } } ); if (ourSets == 0 &amp;&amp; theirSets == 0) { return "No Result"; } else { return (ourSets &gt; theirSets ? "Won " : "Lost ") + ourSets + "-" + theirSets; } } </code></pre> <p>This, apparently, is known in breeze as a "post-construction initializer" and seems like a good solution for my needs in this case as I don't need to do anything with the result, it's a straightforward standalone result of a calculation and is only used for display purposes. Nothing can change on the page that will affect the result, it's already happened.</p> <p>What I still have no idea about is whether this is the most (or even only) way of doing this, or whether I could achieve a similar result with knockout or even standard javascript instead. Doing it within breeze appears to handle the passing of the game entity that's needed to then expose the related "Sets" entity. Just had to be careful to refer to properties with the parentheses added or it all failed.</p> <p>I don't like the idea of having the dataservice littered with model-specific constructors, initializers and functions, however. To my mind, most of what I've done belongs in the "vm.game.js" file and not the generic "dataservice.js" file as it currently is.</p> <p>I'm now going to attempt to shift the code over. It may take me some time to work out the references!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload