gpt4 book ai didi

javascript - 将多个变量从express传递到jade

转载 作者:行者123 更新时间:2023-11-28 18:37:41 25 4
gpt4 key购买 nike

我有一个变量列表,用于检查返回 true 或 false 的条件。这在打印到console.log时有效,但现在我需要在jade模板中渲染它。我收到以下错误。我哪里出错了?

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

});

最佳答案

你必须像这样渲染 View

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

已编辑

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
});
}
});
}
});

关于javascript - 将多个变量从express传递到jade,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36766074/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com