时雨行 2021-08-02 16:40 采纳率: 42.9%
浏览 543
已结题

关于async/await和async的返回值的问题


    draw: async function (json_exe, parentId, json_nowTypeset) {
       
        //答题区
    
        //根据答案自动生成高度
        let answer_height = 0
        let img_number = 0
        if (json_exe.ExeInfo.SubjectiveAnswer) {
            for (let i = 0; i < answer_div.children.length; i++) {
                //是否存在图片,如果存在则获取图片的高度
                let answer_img = answer_div.children[i].getElementsByTagName("img")
                if (answer_img.length === 1) {
                    img_number += answer_img.length
                    let img = new Image()
                    img.src = answer_img[0].src
                    answer_height -= this.subject_row_height
                   
                         img.onload = async function () {
                            img_number--
                            answer_height += img.height
                            return answer_height
                        }
                    
                }
                if (answer_img.length > 1) {
                    answer_height += 60
                }
            }
         }
        } else {
            answer_height = this.subject_default_height
        }
        //是否小于默认高度
        if (answer_height < Subjective.subject_default_height) {
            answer_height = Subjective.subject_default_height
        }
        
        let str_result +=
            '<div class="hex-exe-end" ' +
            'exercise-id="' + json_exe.ExeInfo.ExerciseId + '" ' +
            'exercise-parent-id="' + parentId + '" ' +
            'style="height: ' + answer_height + 'px" ' +
            'exercise-type="' + exerciseType + '"></div>';
        return str_result
    },

这个差不多就是这个方法,之后我在其他js里调用了这个draw,我想用它返回的那个div,

str_insertHTML += xxxx.draw(oneExe, '', this.json_nowTypeset)

但是当我使用.then的时候它提示.then为为解析的函数或者变量

我想问两个问题
1、我想知道我这个async和await的写法是否正确
2、为什么.then会提示这个

  • 写回答

5条回答 默认 最新

  • gzczzzzzz 2021-08-02 16:51
    关注

    你这个await async 关键字怎么还能连一起使用的?
    好乱啊 你这个 await async
    await 后面的函数需要是promise函数才行 .then也一样 promise函数后面才能.then

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 8月13日
  • 修改了问题 8月2日
  • 创建了问题 8月2日

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog