search

Home  >  Q&A  >  body text

javascript - Problem with asynchronous return value in js?

1. The following is the list rendering of my v-for

 <p class="swiper-slide" v-for="bind in binds">
            <p class="bind_box">
              <p class="bind_box_top">
                <p class="bind_box_face"><img :src="bind.face" v-if="bind.face"><img src="../page/baby/images/face_default.png" v-else></p>
                <p class="bind_box_name">{{bind.name}}</p>
              </p>
              <p class="bind_box_main">
                <p class="bind_box_pic"><img :src="bind.id | createdEwm(bind.name,bind.token)"></p>
                <p class="bind_box_text">扫描二维码关注宝贝</p>
              </p>
            </p>
        </p>

2. The following is the method of createdEwm:

createdEwm:function(id,name,token){
        var ewmUrl="bind|"+id+"|"+name//+"|"+token
        var ewmPath=''
        jsbridge.callMethod({
          methodName:"qrGenerate",
          params:{url:ewmUrl,size:150},
          complete:function(data){
            let obj = JSON.parse(data);
            if(obj.errCode=='0'){
              ewmPath=obj.path
            }else{
                alert(obj.errMsg)
                ewmPath=''
            }
            alert(ewmPath)
            return ewmPath
          }
        })
      }

Question: At this time, alert can pop up the returned ob.path data, but the return returned to: src is empty? Isn't the object returned by return createdEwm? Or is the corresponding return now complete?

大家讲道理大家讲道理2823 days ago435

reply all(2)I'll reply

  • ringa_lee

    ringa_lee2017-05-19 10:17:01

    The return of the inner method has nothing to do with the outer method

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-19 10:17:01

    You have to see clearly that jsbridgeyi is already executing the callMethod method, and complete is just an aspect under callMethod. If you return ewmPath, this scope is only under callMethod, not under createdEwm, so the return will be empty

    reply
    0
  • Cancelreply