账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    请求代码优化思路
    39
    0
    生成一个tbody的思路优化(注:只能createElement,只能在方法中生成)async geneTableList():Promise<any>{ let url = 'http://127.0.0.1:5000/test/annotation/genelist?pagesize=20'; url = url + '&pagenum=' + this.pagenum; url = this.filterparam?url + '&filterparam=' + this.filterparam : url; url = this.sortname?url + '&sort={"name":"' + this.sortname + '","isAsc":' + this.isasc+'}' : url; this.listEle.classList.add('el-table') this.listEle.appendChild(this.tbody) var httpRequest = new XMLHttpRequest(); //第一步:建立所需的对象 httpRequest.open('GET', url, true); //第二步:打开连接 将请求参数写在url中 ps:"./Ptest.php?name=test&nameone=testone" httpRequest.send(); //第三步:发送请求 将请求参数写在URL中 let that = this httpRequest.onreadystatechange = function () { if (httpRequest.readyState == 4 && httpRequest.status == 200) { var res = <any>JSON.parse(httpRequest.responseText) ; //获取到json字符串,还需解析 if(res.code == 200){ that.totalPage = res.totalpage res.data.forEach((item:any)=>{ const tr = document.createElement('tr') const tdCheckbox = document.createElement('td') const checkDiv = document.createElement('div') const checkbox = document.createElement('input') checkDiv.classList.add('cell') tdCheckbox.setAttribute('rowspan', '1') tdCheckbox.setAttribute('colspan', '1') checkbox.type = 'checkbox' const tdGene = document.createElement('td') const gene = document.createElement('div') gene.classList.add('cell') tdGene.setAttribute('rowspan', '1') tdGene.setAttribute('colspan', '1') gene.innerText = item.gene gene.setAttribute('value', item.gene) const tdMIDCount = document.createElement('td') const MIDCount = document.createElement('div') MIDCount.classList.add('cell') tdMIDCount.setAttribute('rowspan', '1') tdMIDCount.setAttribute('colspan', '1') MIDCount.innerText = item.MIDcount MIDCount.setAttribute('value', item.gene) const tdE10 = document.createElement('td') const E10 = document.createElement('div') E10.classList.add('cell') tdE10.setAttribute('rowspan', '1') tdE10.setAttribute('colspan', '1') E10.innerText = item.E10.toFixed(2) E10.setAttribute('value', item.gene) tdCheckbox.appendChild(checkDiv) checkDiv.appendChild(checkbox) tdGene.appendChild(gene) tdMIDCount.appendChild(MIDCount) tdE10.appendChild(E10) tr.appendChild(tdCheckbox) tr.appendChild(tdGene) tr.appendChild(tdMIDCount) tr.appendChild(tdE10) that.tbody.appendChild(tr) that.listEle.appendChild(that.tbody) }) } } }; return {tableDom: that.listEle, tablePage: that.totalPage}}
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部