flow-js icon indicating copy to clipboard operation
flow-js copied to clipboard

More complex serialForEach example

Open scottsd opened this issue 11 years ago • 0 comments

Hello,

I'm trying to put together a more complex serialForEach example, which includes "jumping" manually to next step, based on the example in issue #3. step 1: search for the value step 2: if found, just go to next step. If not, search again using different parameters, and go to next step using that value


flow.serialForEach(["refe", "lkajdflkjwernm", "crypto", "poidfgmnermn"], function(val) {
  console.log("Searching for " + val)
      $.ajax({
                type: "GET",
        url: 'https://api.stackexchange.com/2.1/badges?key=U4DMV*8nvpm3EOpvf69Rxw((&site=stackoverflow&order=desc&sort=rank&filter=default',
        data: {inname: val},
                success: this
      })

},function(search_result) {
  console.log('search_result')  
  console.log(search_result)

  var next = this
  if (search_result.items.length > 0) {
    console.log('found')  
    next(search_result.items[0])
  } else {
    console.log('NOT found')  
    //just get the latest badge
      $.ajax({
                type: "GET",
        url: 'https://api.stackexchange.com/2.1/badges?key=U4DMV*8nvpm3EOpvf69Rxw((&site=stackoverflow&order=desc&sort=rank&filter=default',
        data: {},
                success: this
      })

  }

},function(badge) {
  console.log('badge')  
  console.log(badge)  



},function() {
    console.log('This is the end!');
});

There are multiple issues with this sample:

  1. the 'badge' step isn't called with additional data passed as parameters. 'badge' is always undefined.
  2. processing stops after 2nd value in serialForEach array
  3. 'This is the end!' never makes it

How should the code look for this to work?

Thanks

scottsd avatar Dec 09 '13 07:12 scottsd