decoder_rnn = SimpleRNN(32, activation='relu', return_sequences=True)(decoder_embedding, initial_state=encoder_rnn_state)
我试图使条件1和条件2为真,请重定向到第一页。 如果错误,则重定向到第二页。 但是它一直在发生错误。这是日志。
错误[ERR_HTTP_HEADERS_SENT]:将标头发送到客户端后无法设置
答案 0 :(得分:1)
如果要在Array数据中的任何一项与条件匹配的情况下重定向到“ first_page”,或者在没有与条件匹配的条件下重定向到“ second_page”
对代码的最简单的更改是
app.post('/process', function(request, response) {
var i = 0;
while (i < data.length) {
if (data[i].condition1 == condition1 && data[i].condition2 == condition2) {
response.redirect('/first_page');
return; // done, no need to check any more of data
}
i++;
}
response.redirect('/second_page');
});
但是,将Array#some
与if / else一起使用会有效
app.post('/process', function(request, response) {
if (data.some(item => item.condition1 == condition1 && item.condition2 == condition2)) {
response.redirect('/first_page');
} else {
response.redirect('/second_page');
}
});
data.some
将在数据中的任何一项与条件匹配时返回true,否则将返回false
我个人而言,我更喜欢Array.some代码,因为它更整洁,而且对正在发生的事情更明显