我正在尝试在每条推文的新行中显示来自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 }); });I am trying display the results from the twitter api in a new line for each tweet. I get it looking ok in console.log but not when displaying it in express. Currently in express I am using a paragraph tag.<p><%=tweets%></p> What do I need to do to get my array values to show up each on new lines.
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 }); });最满意答案
在HTML中,通常会忽略换行符。 如果您使用像<pre>这样的标签而不是<p>并使用tweets: output.join('\n') ,您应该看到预期的换行符,因为<pre>将按原样显示内容。
In HTML, newlines are generally disregarded. If you use a tag like <pre> though instead of <p> and use tweets: output.join('\n'), you should see newlines as you expect since <pre> will display content as-is.
更多推荐
发布评论