鍍金池/ 問答/HTML/ jQuery中的 循環(huán)問題

jQuery中的 循環(huán)問題

我在點(diǎn)擊查看按鈕選獲取表格某條數(shù)據(jù)的id的時(shí)候,根據(jù)id請(qǐng)求多條數(shù)據(jù),使用each循環(huán)進(jìn)行渲染,點(diǎn)擊完之后,下次點(diǎn)擊會(huì)累計(jì)上次的信息
這是我寫的代碼:

//查看數(shù)據(jù)的商品詳情頁(yè)的數(shù)據(jù)請(qǐng)求
function productDatas(orderNum,type) {

    $.ajax({
        type: 'post',
        data: {orderNo: orderNum},
        url: '/manages/order/query_orderno',
        success: function (data) {
            var item='';
            console.log(data);
            var goodsDatas=data.data.detailList;//goodstype
            console.log(data.data.detailList);
            $.each(goodsDatas,function(i,result){  ///<button type="button" id="lookOrderDatas" class="btn btn-primary">查看</button>
                item += '<tr height="50"><td>'+result.goodstitle+'</td><td>'+result.goodsid+'</td><td>'+result.quantity+'</td><td>'+result.totalprice+'</td><td  style="width: 80px" ><button type="button" id="lookOrderDatas" class="btn btn-primary" style="display: none">查看</button></td></tr>';
                if(result.goodstitle==1){
                    $("#lookOrderDatas").css("display","block");
                }
            });
            $('#productDatas').append(item);
        }
    })

}

這是我的圖片圖片描述

問題出現(xiàn)的環(huán)境背景及自己嘗試過哪些方法

相關(guān)代碼

// 請(qǐng)把代碼文本粘貼到下方(請(qǐng)勿用圖片代替代碼)

你期待的結(jié)果是什么?實(shí)際看到的錯(cuò)誤信息又是什么?

回答
編輯回答
菊外人

你應(yīng)該先清空在添加

2017年2月17日 01:48
編輯回答
野橘

意思是不是多次點(diǎn)擊查看,彈出的dialog內(nèi)容是累加的?$('#productDatas')請(qǐng)?jiān)賏ppend前執(zhí)行一次empty。

2017年12月31日 00:10
編輯回答
魚梓

木有太看懂啊,關(guān)鍵代碼圈出來,問題是啥,想要啥結(jié)果

2018年8月30日 08:15