帖子
帖子
用户
博客
课程
显示全部楼层
1
帖子
0
勋章
12
Y币

[BUG] api.setRefreshHeaderInfo 回调方法不执行 promise then?

[复制链接]
发表于 2016-12-15 18:06:31
本帖最后由 limi58 于 2016-12-15 18:40 编辑

调了半天了,发现 setRefreshHeaderInfo 回调里只要有 promise 都是不执行 promise 里的 then 的,如果把 promise 换成其他的异步加回调的话是可以的,但是我们方法都是用 promise 方式写的,确认这些方法单独用的时候是正常的,只要在 setRefreshHeaderInfo 就不正常了,为何?
api.setRefreshHeaderInfo({
          visible: true,
          loadingImg: 'widget://image/refresh.png',
          bgColor: '#ccc',
          textColor: '#fff',
          textDown: '下拉刷新...',
          textUp: '松开刷新...',
          showTime: true
        }, function() {
          haha().then(res => console.log(res)) // 没打印res
      })




2
帖子
0
勋章
2271
Y币
apiready = function() {
                        api.setRefreshHeaderInfo({
                                visible : true,
                                loadingImg : 'widget://image/refresh.png',
                                bgColor : '#ccc',
                                textColor : '#fff',
                                textDown : '下拉刷新...',
                                textUp : '松开刷新...',
                                showTime : true
                        }, function() {
                                //haha().then( res =   > console.log(res)) // 没打印res
                                runAsync1().then(function(data) {
                                        console.log(data);
                                        return runAsync2();
                                })
                        })
                        function runAsync1() {
                                var p = new Promise(function(resolve, reject) {
                                        //做一些异步操作
                                        setTimeout(function() {
                                                console.log('异步任务1执行完成');
                                                resolve('随便什么数据1');
                                        }, 1000);
                                });
                                return p;
                        }

                };
haha函数怎么来的?res是怎么定义的?
1
帖子
0
勋章
12
Y币
cjapi 发表于 2016-12-15 20:49
apiready = function() {
                        api.setRefreshHeaderInfo({
                                visible : true,

昨天一天都不行,今天上班又可以了。。。。。
1
帖子
0
勋章
12
Y币
cjapi 发表于 2016-12-15 20:49
apiready = function() {
                        api.setRefreshHeaderInfo({
                                visible : true,

问题又出现了,回调里只要有api.ajax就不会执行promise then:
api.setRefreshHeaderInfo({
        visible: true,
        loadingImg: 'widget://image/refresh.png',
        bgColor: '#ccc',
        textColor: '#fff',
        textDown: '下拉刷新...',
        textUp: '松开刷新...',
        showTime: true
      }, function() {
        new Promise((resolve, reject) => {
          api.ajax({
            url: 'http://test**.**:8000/api/home',
            tag: Math.random(),
            timeout: 1111111111,
            method: 'get',
          }, function(ret, err) {
            resolve(123)
          })
        }).then(res => log('res', res)).catch(err => log('err', err)) // 不执行
      })
80
帖子
0
勋章
567
Y币
是APiCloud 的ajax接口没有兼容promise
您需要登录后才可以回帖 登录

本版积分规则