Friday, 17 March 2017

Use local variable in other part of my code

I use Hapi, Vision and Ejs.

I want want to use a variable declared in a route, in a function.

This is my code (I deleted a few lines to make it more readable) :

//my route
server.route({
    method: 'GET',
    path: '/afficher',
    handler: function (req, reply) {
        var ram = [];
        for(var i=0; i < result.rows.length; i++) {
            ram.push(result.rows[i].ram);
        }
            reply(ram);
        });
    }
});


//-----vision rendering hapi-----
const rootHandler = function (request, reply) {

    reply.view('graph', {
        valeursRAM : ram,
    });
};

I want to use the variable ram in the function rootHandler.

Tanks for your help.



via Mat L

No comments:

Post a Comment