【发布时间】:2014-01-05 03:46:34
【问题描述】:
Mongoose 根据需要返回以下数据:
[Object]
0: Object
thread_history: Array[12]
0: Object
__v: 0
_id: "52c5be11be9931f90b000002"
body: "thread message"
uid: "maarten"
__proto__: Object
1: Object
2: Object
3: Object
我使用 socket.io 发出这些数据,然后尝试将数据转换为 html。
通常我会使用以下 for 循环将发出的数据转换为 html
socket.on('thread_history', function (thread_data) {
if(thread_data.thread_history) {
threads_log.push(thread_data);
console.log(threads_log);
var html = '';
for (var i = 0; i < threads_log.length; i++) {
html += '<div class="thread_wrapper">' + (threads_log[i].uid ? threads_log[i].uid : 'Server') + ' - ' + threads_log[i].body + '</div>';
}
thread_content.innerHTML = html;
thread_content.scrollTop = content.scrollHeight;
}
else {
console.log("There is a problem: ", thread_data);
}
});
当然,这不适用于 mongoose 返回的数据。
我根本无法访问这些对象,有人可以帮助我吗?我做错了什么?
【问题讨论】:
-
你遇到了什么错误?
-
我的控制台中没有出现任何错误,但是,创建了 1 个 div,其中包含“服务器 - 未定义”。所以它可能在那里失败
标签: javascript for-loop mongoose