lundi 27 juin 2016

Display dialogs in a loop and act on the accept event.

In my Nativescript app I have a loop and want to display a dialog for each item being iterated over. When the dialog displays it contains "Accept" and "Reject" options, both of which when clicked I would like to call a method which I pass the iterated item into. The issue is since the option selection returns a promise I lose the reference to the iterated item. What can I do to get around this? Here's an example of my code.

function _showPendingConnections() {    
    for (var i = 0; i < ViewModel.pendingConnections.length; i++) {
        var pendingConnection = ViewModel.pendingConnections[i];
        dialog.confirm({
            message: pendingConnection.PatientFirstName + " would like to share their glucose readings with you.",
            okButtonText:"Accept",
            cancelButtonText:"Reject"                                    
        }).then(function(result) {
            if(result === true) {
                ViewModel.acceptConnection(pendingConnection);
            } else {
                ViewModel.removeConnection(pendingConnection);
            }            
        });
    }
}

Aucun commentaire:

Enregistrer un commentaire