Note that there are some explanatory texts on larger screens.

plurals
  1. POdojo/Deferred chaining mechanism not respecting async call
    primarykey
    data
    text
    <p>I'm quite new to dojo, but I have a certain error dealing with the Deferred API I can't help</p> <p>my invoking code is</p> <pre><code>function openEditor(id, fieldName) { editOptionsDialog_fetchData(id, fieldName).then(function(data){ console.log("done!"); }); console.log("leaving openEditor!"); } </code></pre> <p>which calls this function</p> <pre><code>function editOptionsDialog_fetchData(id, fieldName) { require(["dojo/ready", "dojo/data/ObjectStore", "dojo/Deferred"], function(ready, ObjectStore, Deferred) { var store; var def; switch (fieldName) { case "degree": store = new degreeStore(); def = store.getJsonData(); break; case "faculty": store = new facultyStore(); def = store.getJsonData(); break; default: console.log("error in editOptionsDialog_fetchData: " + fieldName); } return def.then(function(data){ store.data = data.items; editOptionsDialog_select.setStore(new ObjectStore({ objectStore : store })); editOptionsDialog_select.store.query({ "id" : id }); editOptionsDialog_select.startup(); }); }); } </code></pre> <p>where store.getJsonData() creates a Deferred, which I want to use for chaining the Deferred resolving (see additional code after the main text).</p> <p>The error I receive is</p> <pre><code>editOptionsDialog_fetchData(id, fieldName).then(function(data)...) is undefined </code></pre> <p>Since the error message appears right after accessing the openEditor function, it is clear, that the value of the function call has to be undefined, since the callback is not yet done.</p> <p>My question is, where this misunderstanding of the Deferred API must be within my code, since the purpose is to evaluate the function call of editOptionsDialog AS SOON AS the async call is done and called backed, AND NOT BEFORE this call has finished (in the state where the function call still leads to undefined, but I thought this is the purpose of the then-return).</p> <p>Thx for your help</p> <p>--- additional code for getJsonData() ---</p> <pre><code>getJsonData: function() { return xhr(this.handlerUrl, { handleAs: "json", method: "POST", data: { action: "getJsonData" } }).then(function(data){ return data; }, function(err){ alert("Data cannot be fetched in degreeStore.getJsonData! " + err); }); } </code></pre>
    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.
 

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