У меня есть вызов API, где я получаю массив в ответ. Теперь я хочу открыть jQuery Подтвердить , зацикливая ответ по очереди, но проблема в том, что они открываются все сразу. Вот код
axios.post('/orders/ask-for-order-price', {ids: order_ids}).then((response) => {
if (response.status === 200) {
let orders = response.data
$.each(orders, function (index, item) {
if (item.ask_for_price === true) {
showPricePopup(index, item.address, item.order_type, item.client_name)
}
})
}
}).catch((error) => {
console.info(error)
})
showPricePopup = (id, address, type, client_name) => {
$.confirm({
title: 'Please enter order price for ',
content: '' +
'<form action="" class="formName">' +
'<div class="form-group">' +
'<label><strong>' + type + '</strong> at <strong>' + address + '</strong> by <strong>' + client_name + '</strong></label>' +
'<input type="text" placeholder="Enter the price here" class="price form-control" required />' +
'</div>' +
'</form>',
buttons: {
formSubmit: {
text: 'Submit',
btnClass: 'btn-blue',
action: function () {
var price = this.$content.find('.price').val();
if (!price) {
$.alert('provide a valid price');
return false;
}
$.alert('Your price is ' + price);
}
},
cancel: function () {
//close
},
},
onContentReady: function () {
// bind to events
var jc = this;
this.$content.find('form').on('submit', function (e) {
// if the user submits the form by pressing enter in the field.
e.preventDefault();
jc.$$formSubmit.trigger('click'); // reference the button and click it
});
}
});
}
РЕДАКТИРОВАТЬ response.data
выглядит так
{
"1": {
"ask_for_price": true,
"order_type": "Construction New",
"address": "3685 Simons Hollow Road, Hanover Township, PA",
"created_at": "03/16/20",
"client_name": "Muhammad Ahmad Baig",
},
"2": {
"ask_for_price": true,
"order_type": "Phase I",
"address": "4744 Horizon Circle, University Place, WA",
"created_at": "03/16/20",
"client_name": "Muhammad Ahmad Baig",
},
"3": {
"ask_for_price": true,
"order_type": "ETS",
"address": "1491 Gambler Lane, ALLENDALE, IL",
"created_at": "03/16/20",
"client_name": "Muhammad Ahmad Baig",
},
"4": {
"ask_for_price": true,
"order_type": "Property Condition Assesment",
"address": "58 Glenview Drive, Corpus Christi, TX",
"created_at": "03/16/20",
"client_name": "Muhammad Ahmad Baig",
},
"5": {
"ask_for_price": true,
"order_type": "Property Condition Assesment (Short Form)",
"address": "858 Duncan Avenue, Scarsdale, NY",
"created_at": "03/16/20",
"client_name": "Muhammad Ahmad Baig",
},
"6": {
"ask_for_price": true,
"order_type": "Plan and Cost Review",
"address": "3116 Wolf Pen Road, Pacifica, CA",
"created_at": "03/16/20",
"client_name": "Muhammad Ahmad Baig",
},
}