我正在尝试在每条推文的新行中显示来自twitter api的结果。我在console.log中看起来没问题,但在Express中显示它时却没有。目前我在使用段落标记。<p><%=tweets%></p>
我需要做什么才能让我的数组值显示在新行上。
router.get('/', function(req, res) {
var output = [];
twitter.get('statuses/user_timeline',{user_id:xxxxxxx, screen_name:'xxxxxxxxx'}, function(error, params, response){
if(error) throw error;
for(var text in params){
output.push(params[text].text); //comes in a huge string no '/n' allowed
}
res.render('index', {
title: 'Home Page', //renders fine
tweets: output //renders as a large string I try output.join("\n") does not render
});
});
答案 0 :(得分:0)
在HTML中,通常会忽略换行符。如果您使用<pre>
之类的标记而不是<p>
并使用tweets: output.join('\n')
,那么您应该看到预期的换行符,因为<pre>
将按原样显示内容。