search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Update multiple Event to server in loop

Asked by Thomas Lee
6 years ago.

I have DayPilot.Scheduler having multiple events.
I need to update real Event ID after handle from Server, Server will return the real Event ID
I will replace EventID from ui() with Event Id from Server.
But I have a problem that, not all the Events in Scheduler are updated.

Here is my code:

var Events = dpPrdPkg.events.list;
if (Events.length > 0) {
for (var i = 0; i < Events.length; i++) {
var CurrentEv = dpPrdPkg.events.find(Events[i].id);
$.ajax({
type: "POST",
async: true,
url: Url,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if (response.length == 3) {

if (response[0] !== "" && response[1] !== "") {
value = 1;
/* Update Client-side */
for (var i = 0; i < dpPrdPkg.events.list.length; i++) {
var e = dpPrdPkg.events.list[i];

if (e.id == response[0]) {
e.id = response[1];

/*2018/04/07: replace Bubble-HTML */
e.bubbleHtml = e.bubbleHtml.replace(e.id, response[1]);

dpPrdPkg.update();
}
}

} else {
dpPrdPkg.message(response[2]);
}
}
}, error: function (response) {
dpPrdPkg.message("Approve Event FAILED " + response.text);
}
});

}
}

Thank in advance,
Thomas Lee

Answer posted by Dan Letecky [DayPilot]
6 years ago.

If you have 300 events in events.list this code will fire 300 HTTP requests which will complete in more or less random order. In the success callback, you are requesting a full update() - the update is partially asynchronous and it will not work properly if you modify events.list before it finishes.

Try replacing this logic with a single HTTP request and a single update() call.

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.