2

I have a dude, I want to pass a var between two functions... How I can do that?

For example my code is the next

      beforeedit: 

            function preditar(editor, e, eOpts) {
            var grid = Ext.getCmp('gridTabla'); // or e.grid
            var hoy = new Date();

            dia = hoy.getDate(); 

            if(dia<10)
                {
                    dia=String("0"+dia);

                }

            mes = hoy.getMonth();

            if(mes<10)
            {
                    mes=String("0"+mes);

            }
            anio= hoy.getFullYear();
            fecha_actual = String(anio+""+mes+""+dia);
            //alert(fecha_actual);

            var mola = e.record.data.ESTLOT;
            alert(mola);

            if (e.record.data.ESTLOT === '02') {
                if (e.record.data.FECMOD === fecha_actual)
                 {
                e.cancel = false; //permite
                 }
                else{
                    e.cancel = true; //mo permite
                }

            }  else
            {
                e.cancel = false; //permite
            }

        },

         edit:

             function editar(e, context){
             var record = context.record;
             var recordData = record.getData();

             recordData.Funcionalidad = 'Modificar';
             alert(JSON.stringify(recordData));


             Ext.Ajax.request({
                 url: 'http://localhost:8080/MyMaver/ServletTablaLotes',
                 method: 'POST',

                 // merge row data with other params
                 params: recordData
             });
         }
        }

I would like to pass for example the var mola to the edit function... thanks for all, I don't know how I can do that... I don't find any example in internet I only find to pass a var to a function but not between functions.

1 Answer 1

4

Declare it outside the functions. Or return it from the first, and pass it to the second function.

Something like this maybe?

{
    mola: '',
    beforeedit:
    function preditar(editor, e, eOpts) {
        var grid = Ext.getCmp('gridTabla'); // or e.grid
        var hoy = new Date();

        dia = hoy.getDate();

        if (dia < 10) {
            dia = String("0" + dia);

        }

        mes = hoy.getMonth();

        if (mes < 10) {
            mes = String("0" + mes);

        }
        anio = hoy.getFullYear();
        fecha_actual = String(anio + "" + mes + "" + dia);
        //alert(fecha_actual);

        mola = e.record.data.ESTLOT;
        alert(mola);

        if (e.record.data.ESTLOT === '02') {
            if (e.record.data.FECMOD === fecha_actual) {
                e.cancel = false; //permite
            } else {
                e.cancel = true; //mo permite
            }

        } else {
            e.cancel = false; //permite
        }

    },

    edit:

    function editar(e, context) {
        var record = context.record;
        var recordData = record.getData();

        recordData.Funcionalidad = 'Modificar';
        alert(JSON.stringify(recordData));

        mola && alert(mola);

        Ext.Ajax.request({
            url: 'http://localhost:8080/MyMaver/ServletTablaLotes',
            method: 'POST',

            // merge row data with other params
            params: recordData
        });
    }
}

}
Sign up to request clarification or add additional context in comments.

8 Comments

Isn't this more of a comment than an answer?
I think it depends on the context of the code, as to what the best answer is.
@harsha well, it could be expanded
@Antonis : Ah,that looks better! :-)
@harsha still, it's a stupid sample of code =P He can write it better depending on what he wants exactly.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.