EasyUI Forum
September 13, 2025, 02:22:19 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: how to add parameters to messager.alert callback?  (Read 6185 times)
r2ferna
Newbie
*
Posts: 21


View Profile
« 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.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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);
  });
})();
}
}
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!