在节点和表达式中循环遍历 JSON
Looping through JSON in node and express
我正在尝试在每条推文的新行中显示来自推特 api 的结果。我在控制台中看起来不错.log但在快速显示它时却不行。目前在表达中,我正在使用段落标签。<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
});
});
在 HTML 中,换行符通常被忽略。如果您使用类似 <pre>
的标签而不是 <p>
并使用 tweets: output.join(''n')
,您应该按预期看到换行符,因为<pre>
将按原样显示内容。
相关文章:
- 循环遍历以数组为值的Javascript对象
- 循环遍历包含另一个表单的表单
- JS.循环遍历多维数组,以计数元素在每列中的出现次数
- js循环遍历单击的元素子节点
- 根据PHP中数组的长度在Google Maps API中循环遍历标记
- 循环遍历元素jquery选择器
- 无法在javascript中循环遍历对象数组
- 在循环遍历对象 HTMLDivElement 时,应用 ChileNode 样式 zindex 在 firefox 和
- 如何在DataTablesjQuery中循环遍历所有行
- 使用函数for循环遍历对象以更改值,然后返回结果
- 遍历 jQuery:循环遍历子项
- 循环遍历平行层
- 循环遍历 jqGrid 中的 colModels 名称
- jQuery 插件不会循环遍历匹配的项目
- 循环遍历 JSON 对象
- 一次循环遍历一组
- 循环遍历表行,获取总计和更新行
- 循环遍历 DOM 元素时,是否有 for 循环的替代方法
- 使用 ajax、PHP 和 Javascript 循环遍历 JSON 文件
- 循环遍历单选按钮(20 组,每组 3 个),并检查是否选中了每个组