繁体   English   中英

如何从画布中删除上传的图像(如果有)?

[英]How to remove uploaded image(if any) from canvas?

在我的代码中,如果有图像被成功删除,但是当画布中有多个图像时,我怎么知道我必须调用 Remove_image() 函数多少次? 我的条件是,如果身体发现画布为空,则上传图像,否则删除上传的图像。

这是我的代码

cy.get('body').each((body) => {
        if (body.find(':nth-child(2) > .front-upload > :nth-child(2) > .table > .table-cell').length > 0) {

            const filepath = "Front.jpg"
            imageupload.fileuploadInput().attachFile(filepath, { subjectType: 'drag-n-drop' })
            cy.wait(60000)
            cy.Flip_image()
        }
        else {

            // REMOVE ELEMENT
            cy.log('Remove Image')
           // There is 5 uploaded image that's why this function call 5 times But this is not right structure.       
            cy.Remove_image()
            cy.Remove_image()
            cy.Remove_image()
            cy.Remove_image()
            cy.Remove_image()
            
            // UPLOAD IMAGE
            cy.wait(1000)
            const filepath = "Front.jpg"
            imageupload.fileuploadInput().attachFile(filepath, { subjectType: 'drag-n-drop' })
            cy.wait(60000)
            cy.Flip_image()
        }

    })

这就是我的处理方式,

假设有与单元格一样多的图像

cy.get(':nth-child(2) > .front-upload > :nth-child(2) > .table')
  .then($table => {

    const imageCount = $table.find('.table-cell').length;  

    for (let i = 0; i < imageCount; i++) {
      cy.Remove_image()
    })

    // UPLOAD IMAGE
    cy.wait(1000)
    const filepath = "Front.jpg"
    imageupload.fileuploadInput().attachFile(filepath, { subjectType: 'drag-n-drop' })
    cy.wait(60000)
    cy.Flip_image()

  })

如果某些单元格可能为空,您可以计算<img>标签

const imageCount = $table.find('img').length;  

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM