我需要使用 Google 表格和从Canvas中提取的数据来完成一项(看似)简单的任务
确定讨论帖,例如按学生计数
例如:
- 学生 A 在讨论区发帖
- 学生 B 在学生 A 的帖子上点击了“赞”按钮
- 我需要看到学生 B 的动作计数为 1
这是我到目前为止所做的......
我找到了这两个示例并将它们作为我的起点:
- 这完美无缺
- 我可以统计学生讨论区的帖子
- 我确认计数是准确的
- 下面是我正在使用的代码片段
if (typeof users[userId] !== 'undefined') {
if (typeof counts[userId] === 'undefined') {
counts[userId] = 1;
}
else {
counts[userId]++;
}
}
- 这就是我要解决的问题
- 下面是我正在使用的代码片段
if (typeof users[userId] !== 'undefined' && typeof entries[entry].rating_sum !== 'undefined') {
if (typeof counts[userId] === 'undefined') {
counts[userId] = entries[entry].rating_sum;
}
else {
counts[userId] += entries[entry].rating_sum;
}
}
最初,这没有返回任何结果......这很奇怪,因为我已经手动验证了学生帖子实际上有很多喜欢......而且我的第一个测试只计算所有讨论板帖子返回一个准确的计数。
我修改了代码以返回所有内容,而不管entries[entry].rating_sum
值如何
if (typeof users[userId] !== 'undefined') {
if (typeof counts[userId] === 'undefined') {
counts[userId] = entries[entry].rating_sum;
}
else {
counts[userId] += entries[entry].rating_sum;
}
}
我所看到的是所有entries[entry].rating_sum
值都是“未定义的”
我不确定如何确定根本原因 - 我相信代码按预期工作
感谢您的见解
谢谢!