javascript - Nested promises in a while cycle not working synchronously -


i writing sharepoint app (for project server) in javascript , usign asynchronous calls query data server.

these async calls rely on eachother , in cycles.

to idea of problem:

there multiple projects on project server. want read every projects. go through projects 1 one , read properties. go :

$(document).ready(function () {     projcontext = ps.projectcontext.get_current();      //i read projects when page loads     var projectspromise = getallprojects();     projectspromise.done(function (resultprojects) {         //if data use result in next function         gothroughprojects(resultprojects);     });      projectspromise.fail(function (result) {         var error = result;     console.log(error);     });  });  function gothroughprojects(projectlist) {     var projenum = projectlist.getenumerator();     while (projenum.movenext()) { //i'm going through projects 1 one         var project = projenum.get_current();         alert("y - " + project.get_name()); //y alert          getproperties(project).then(             function (resultproperties) {                 alert("x - got properties"); //x alert             },             function (sender, args) {                 alert(args.get_message());             }        );    } } 

in example, alerts in order, not quite right me. alerts starting y shown 1 after another, without x alert inbetween. (so go yyyxxx if there 3 projects, example instead of yxyxyx).

how can chain them, run in more synchronous way?

so in kind of pseudo code like:

first async call read projects each project {     second async call read selected projects data     each property     {         / maybe third level of async call     } } 


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -