jeudi 25 juillet 2019

How to solve this Jquery loop condition problem?

I'm having a problem with loop geting specific value from html where is a condition.

I have to get values from div.column-ui.to-pay-column-ui.to-pay-column-lq span IF .column-ui.days-after-column-ui has div.error-bg-ui.days-after-ui inside

below some of my code

<div class="invoices-table-ui table-lq" style="display: block;">
    <div class="row-ui load-erp-invoice-details-lq parent-container-reload-lq" data-url="/profil-klienta,6?&amp;deeper-lvl&amp;erp-data&amp;invoice-erp">

    <div class="column-ui days-after-column-ui">
        <!-- rivets: if o.DaysAfterExists -->
    </div>
    <div class="column-ui"></div>
    <div class="column-ui to-pay-column-ui to-pay-column-lq">
        <!-- rivets: if o.ToPayExists --><span>2 685,51 PLN</span>
        <!-- rivets: if o.ToReturnExists -->
    </div>
</div>
<div class="row-ui load-erp-invoice-details-lq parent-container-reload-lq" data-url="/profil-klienta,6?&amp;deeper-lvl&amp;erp-data&amp;invoice-erp">

    <div class="column-ui days-after-column-ui">
        <!-- rivets: if o.DaysAfterExists -->
    </div>
    <div class="column-ui"></div>

    <div class="column-ui to-pay-column-ui to-pay-column-lq">
        <!-- rivets: if o.ToPayExists -->
        <!-- rivets: if o.ToReturnExists -->
    </div>
</div>
<div class="row-ui load-erp-invoice-details-lq parent-container-reload-lq" data-url="/profil-klienta,6?&amp;deeper-lvl&amp;erp-data&amp;invoice-erp">

    <div class="column-ui days-after-column-ui">
        <!-- rivets: if o.DaysAfterExists -->
        <div class="error-bg-ui days-after-ui">
            1 dni po terminie
        </div>
    </div>
    <div class="column-ui"></div>
    <div class="column-ui to-pay-column-ui to-pay-column-lq">
        <!-- rivets: if o.ToPayExists --><span>1 339,41 PLN</span>
        <!-- rivets: if o.ToReturnExists -->
    </div>
</div>

<script>
var companiesList = [];

 $(document).ready(function(){  



$('.invoices-table-ui.table-lq').each(function(index, element){

    companiesList[index] = {};

    var result = null;

    ( $(element).find(".column-ui.days-after-column-ui").has("div.error-bg-ui.days-after-ui").length ? result = $(element).find('.column-ui.to-pay-column-ui.to-pay-column-lq span').text().trim() : result = 0 )



    companiesList[index] = result;


});

console.log(companiesList);

 });
</script>

Result what I got is

["2 685,51 PLN1 339,41 PLN"]

but I need only

["1 339,41 PLN"]

Thank you for any suggestions.

Aucun commentaire:

Enregistrer un commentaire