EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: r2ferna on November 06, 2015, 01:05:03 PM



Title: how to add parameters to messager.alert callback?
Post by: r2ferna on November 06, 2015, 01:05:03 PM
Hi,
I wrote this function to display/alert any number of messages.
I want to fire a callback, for every message, when the OK button is presed. So I wrote the second function: mssagerAlertCallBack.

Code:
function tjs1_muestraTodosLosMensajes (pMensaje) {
for (var i = pMensaje.length - 1; i>=0; i--) {
  var numMsjs = pMensaje.length;  var numMsj = i+1;  var mensaje = pMensaje[i];
  var titulo = "(Msje " + numMsj + "/" + numMsjs + ") - " + mensaje.msj_title;
  var oIcons = {"E" : "error", "Q": "question", "I": "info", "W": "warning"};
  var icon = oIcons[mensaje.msj_type];
  var win = $.messager.alert(titulo, mensaje.msj_text, icon, function(){
  if (typeof(mssagerAlertCallBack)==='function') mssagerAlertCallBack(numMsj,numMsjs,mensaje);
  });
  //win.window({closable:false});
}
}

    function mssagerAlertCallBack(numMsj,numMsjs,mensaje){
        console.log('numMsj=',numMsj,numMsjs,mensaje);
    }

I am testing with 5 messages.
The messager.alert display all messages ok, From 1 to 5.
But the mssagerAlertCallBack function displays allways the same data, variable numMsj never changes !?

I have tried some codes with no luck.
Please can you help me?

MTIA.


Title: Re: how to add parameters to messager.alert callback?
Post by: stworthy on November 07, 2015, 05:47:46 PM
Please try this code instead.
Code:
function tjs1_muestraTodosLosMensajes (pMensaje) {
for (var i = pMensaje.length - 1; i>=0; i--) {
(function(){
  var numMsjs = pMensaje.length;  var numMsj = i+1;  var mensaje = pMensaje[i];
  var titulo = "(Msje " + numMsj + "/" + numMsjs + ") - " + mensaje.msj_title;
  var oIcons = {"E" : "error", "Q": "question", "I": "info", "W": "warning"};
  var icon = oIcons[mensaje.msj_type];
  var win = $.messager.alert(titulo, mensaje.msj_text, icon, function(){
  if (typeof(mssagerAlertCallBack)==='function') mssagerAlertCallBack(numMsj,numMsjs,mensaje);
  });
})();
}
}