Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>as a note you wrote you do this</p> <p><code>myAddress.Get("city").MyCityName</code></p> <p>when it should be</p> <p><code>myAddress.get("city").get("MyCityName")</code></p> <p>or</p> <p><code>myAddress.getPath("city.MyCityName")</code></p> <p>With that out of the way, I think your question is "<strong>How do I not load the city object until I want to?</strong>".</p> <p>Assuming you are using datasources, you need to manage in your datasource when you request the city object. So in <code>retrieveRecord</code> in your datasource simply don't fire the request, and call <code>dataSourceDidComplete</code> with the appropriate arguments (look in the datasource.js file) so the city record is not in the <code>BUSY</code> state. You are basically telling the store the record was loaded, but you pass an empty hash, so the record has no data.</p> <p>Of course the problem with this is at some point you will need to retrieve the record. You could define a global like <code>App.WANTS_CITY</code> and in <code>retrieveRecords</code> only do the retrieve when you want the city. You need to manage the value of that trigger; statecharts are a good place to do this.</p> <p>Another part of your question was "<strong>How do I load a bunch of records at once, instead of one request for each record?</strong>"</p> <p>Note on the datasource there is a method <code>retrieveRecords</code>. You can define your own implementation to this method, which would allow you to fetch any records you want -- that avoids N requests for N child records -- you can do them all in one request.</p> <p>Finally, personally, I tend to write an API layer with methods like </p> <p><code>getAddress</code> and <code>getCity</code></p> <p>and invoke my API appropriately, when I actually want the objects. Part of this approach is I have a very light datasource -- I basically bail out of all the create/update/fetch methods depending on what my API layer handles. I use the <code>pushRetrieve</code> and related methods to update the store. </p> <p>I do this because the store uses in datasources in a very rigid way. I like more flexibility; not all server APIs work in the same way.</p>
    singulars
    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