简体   繁体   中英

Pass multiple variables from express to jade

I have a list of variables that check against a condition to return as true or false. This works when printing to console.log but now I need to render this in a jade template. I am receiving the following error. Where am I going wrong?

Cannot read property 'success' of undefined

Jade

  #firstlast #{info.success}

JS

  var fInitialUnderscoreLastName = fInitial + '_' + lastName + email;
  verifier.verify(fInitialUnderscoreLastName, function( err, info ){
    if( err ) console.log(err);
    else{
      var result = info.success;
      console.log( "Info: " + info.info );
    }
  });

  var firstNameUnderscoreLInitial = firstName + '_' + lInitial + email;
  verifier.verify(firstNameUnderscoreLInitial, function( err, info ){
    if( err ) console.log(err);
    else{
      var result = info.success;
      console.log( "Info: " + info.info );
    }
  });

  res.render('index', {
    fInitialUnderscoreLastName: result
    firstNameUnderscoreLInitial: result

  });

You have to render the view like this

res.render('yourView',  {
  "info": {"success": info.success, "info" : info.info},
  "variable2": "value",
  "variable3" : "value"
});

Edited

var fInitialUnderscoreLastName = fInitial + '_' + lastName + email;
var firstNameUnderscoreLInitial = firstName + '_' + lInitial + email;
verifier.verify(fInitialUnderscoreLastName, function( err, info ){
    if( err ) console.log(err);
    else{
      var resultA= info.success;
      verifier.verify(firstNameUnderscoreLInitial, function( err, info ){
        if( err ) console.log(err);
        else{
          var resultB = info.success;
          console.log( "Info: " + info.info );
          res.render('index', {
          "resultA": resultA,
          "resultB": resultB
          });
       }
    });
    }
  });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM