在更新记录的div数显示基于记录

时间:2014-12-30 09:27:35

标签: javascript jquery

当我要插入记录时,我可以插入多条记录。当我点击添加更多时,我添加了更多按钮,在jquery的帮助下创建克隆我的代码

$(document).ready(function () {
    //alert("auction-company");
    var divLength = 1;
    var locationLength = 2;
    $("#addMore").on('click', function () {
        //alert("auction-company");
        var cloneObj = $('.toClone').clone().removeClass('toClone');
        $(cloneObj).attr('id', 'addLocations' + divLength);
        $(cloneObj).find('span[id="locationCounter"]').attr('id', 'locationCounter' + locationLength).html(locationLength);
        /* for element ids increment starting */
        $(cloneObj).find('input[id="auctionLocationName0"]').attr('id', 'auctionLocationName' + divLength).val('');
        $(cloneObj).find('input[id="auctionLocationAddress0"]').attr('id', 'auctionLocationAddress' + divLength).val('');
        $(cloneObj).find('input[id="auctionLocationCity0"]').attr('id', 'auctionLocationCity' + divLength).val('');
        $(cloneObj).find('select[id="auctionLocationState0"]').attr('id', 'auctionLocationState' + divLength).val('');
        $(cloneObj).find('input[id="auctionLocationZipcode0"]').attr('id', 'auctionLocationZipcode' + divLength).val('');
        $(cloneObj).find('input[id="auctionLocationPhone0"]').attr('id', 'auctionLocationPhone' + divLength).val('');
        /* for element ids increment ending */
        $(cloneObj).find('div[class="tools"] a[id="firstRowRemoveDisable"]').addClass('remove');
        $("#toAppend").append(cloneObj);
        divLength++;
        locationLength++;
    });
});

它运行正常,但是当我使用jquery ajax进行更新时,如何显示2个div及其记录。 jQuery ajax和dataTypejson。这是我的更新代码

var auctionComapnyLocation = data.auctionResponseArray;
for (var auctionCompanyLocationLoop = 0; auctionCompanyLocationLoop < auctionComapnyLocation.length; auctionCompanyLocationLoop++) {
    $("#addLocations" + auctionCompanyLocationLoop).show(); 

    var cloneObj = $("#addLocations" + auctionCompanyLocationLoop).clone();
    $(cloneObj).removeClass('toClone');
    $(cloneObj).find('div[class="tools"] a[id="firstRowRemoveDisable"]').addClass('remove');
    //$(cloneObj).find('span[id="locationCounter"]').attr('id', 'locationCounter' + auctionCompanyLocationLoop).html(auctionCompanyLocationLoop);
    $("#toAppend").append(cloneObj);
    //$("#auctionLocationName").val(data.auctionResponseArray.auctionLocationName);
    /*$("#auctionLocationName").val(data.auctionResponseArray.auctionLocationName);
    $("#auctionLocationAddress").val(data.auctionResponseArray.auctionLocationAddress);
    $("#auctionLocationCity").val(data.auctionResponseArray.auctionLocationCity);
    $("#auctionLocationState").val(data.auctionResponseArray.auctionLocationState);
    $("#auctionLocationZipcode").val(data.auctionResponseArray.auctionLocationZipcode);
    $("#auctionLocationPhone").val(data.auctionResponseArray.auctionLocationPhone);
    */

}

0 个答案:

没有答案