Meteor集合find()方法即使已订阅也未定义(Meteor collection find() method is undefined even though its subscribed)
我正在尝试实现一个照片查看器应用程序,它将图像URL和它所属的用户ID存储在一个集合中。 当我尝试Collection.findOne时,它总是返回null。
var name = Meteor.user().username; var message = $('.action-textarea').val(); var userId = Meteor.userId(); var file = $("#input-photo").get(0).files[0]; if(file) { fsFile = new FS.File(file); var id = PostGeneralImages.insert(fsFile, function(err, result) { if(err) { throw new Meteor.Error(err); } else { var imageLoc = '/cfs/files/PostImages/' + result._id; PostImages.insert({ generalId: result._id, userId: Meteor.userId(), username: Meteor.user().username, imageLoc: imageLoc }); } }); } var imagePath = PostImages.findOne({generalId: id._id}).imageLoc; console.log(imagePath);
在控制台上未定义imagePath。 但是当我在控制台中尝试findOne方法时,它成功返回了想要的对象。 我已经发布并订阅了该系列。
I'm trying to implement a photo viewer app that stores image url and it's belonging user id in a collection. When I try to Collection.findOne that value it always returns null.
var name = Meteor.user().username; var message = $('.action-textarea').val(); var userId = Meteor.userId(); var file = $("#input-photo").get(0).files[0]; if(file) { fsFile = new FS.File(file); var id = PostGeneralImages.insert(fsFile, function(err, result) { if(err) { throw new Meteor.Error(err); } else { var imageLoc = '/cfs/files/PostImages/' + result._id; PostImages.insert({ generalId: result._id, userId: Meteor.userId(), username: Meteor.user().username, imageLoc: imageLoc }); } }); } var imagePath = PostImages.findOne({generalId: id._id}).imageLoc; console.log(imagePath);
imagePath is undefined on console. But when I try findOne method in console it successfully returns the wanted object. I'm already publishing and subscribing that collection.
原文:https://stackoverflow.com/questions/35514324
最满意答案
假设您的表按日期排序(它在图片中),那么可以使用
VLOOKUP
解决第一个问题=VLOOKUP("1",A1:C6,3,0)
将
"1"
替换为新表中包含ID1
单元格。对于问题2,您可以使用以下公式,再次使用新表中包含ID
1
单元格替换=1
{=MEDIAN(IF(A1:A6=1,C1:C6,""))}
注意,这是一个数组公式,你不直接键入大括号
{}
,但只需按CTRL + SHIFT + ENTER ,而不是输入公式时只需输入这可以通过创建像这样的数组
{12,23,"","",""}
并取这些数字的中位数来实现。MEDIAN
忽略字符串,因此根据需要给出中间值12和23(ID 1的示例)Assuming your table is ordered by date (which it is in the picture), then the first question can be solved using a
VLOOKUP
=VLOOKUP("1",A1:C6,3,0)
Replace
"1"
which whichever cell contains the ID1
in your new table.For question 2, you can use the following formula, again replacing
=1
with whichever cell contains ID1
in your new table{=MEDIAN(IF(A1:A6=1,C1:C6,""))}
Note, this is an array formula, you don't type the curly brackets
{}
directly, but simple press CTRL+SHIFT+ENTER, rather than just ENTER when entering the formulaThis works by creating an array like this
{12,23,"","",""}
and taking the median of those numbers.MEDIAN
ignores the strings so gives you the median of 12 and 23, as required (example for ID 1)
相关问答
更多-
我认为这可能适合你。 首先,这是我如何定义我的测试表和测试数据: declare @stock table ( transId int not null identity(1,1), [date] date not null, -- use datetime if not using SQL Server 2008 input decimal(7,2) null, [output] decimal(7,2) null ); insert into @stock values ('1/2 ...
-
如何对keypup进行计算,对于多行,一次一个(How to do a calculation on keypup, for several rows, one at a time)[2022-09-20]
至少有一个问题是.keyup()方法需要一个函数。 在您的示例中使用calculate的方式,您在添加事件时立即调用该函数。 为避免这种情况,您可以执行以下操作: $('#p1').keyup(function () { calculate('#p1') }); 另一种选择是让calculate函数返回一个函数引用: function calculate(input) { return function () { $(input + 'Total').val($(input).va ... -
插件作者在这里。 我在http://c17r.github.io/jAutoCalc/sample更新了示例,以包含动态添加/删除行。 整个事件以一种树状结构运行场外事件; 当事情发生变化时,它会有点偏离轨道。 最简单的方法是包装你的代码,将jAutoCalc连接到它自己的函数中 function autoCalcSetup() { $('form[name=cart]').jAutoCalc('destroy'); $('form[name=cart] tr[name=line_items ...
-
分区大计算?(Partitioning A Big Calculation?)[2022-08-30]
我在编程中学到的第一件事就是当你不知道如何编写代码时,首先写出你自己用来解决它的过程(算法),一步一步,然后看看如何翻译那要编码。 听起来像是一个很好的第一步,你可以写出如何在纸上解决问题 - 而不用担心分区问题。 我知道你的问题不是微不足道的,但我会用一个求和的例子。 要查找所有记录的总数,您需要记录0 +记录1 +记录2 + ... +记录2499 =总和。 有了这个,你可以去看看它是否可以分区。 另外,这很容易做到,因为加法是关联的。 分组操作,这是一个分区。 现在,如果您无法找到手动分区计算的方法, ... -
好的,在biziclops提示的帮助下,我找到了CASE语法,现在得到了一个解决方案: SELECT wt.begin, wt.end, CASE WHEN strftime('%w', wt.begin)='1' THEN Mon WHEN strftime('%w', wt.begin)='2' THEN Tue WHEN strftime('%w', wt.begin)='3' THEN Wed WHEN strftime('%w', wt.begin)='4' THE ...
-
Sql Server:选择查询并逐行计算行(Sql Server : Select query with calculation on rows one after another)[2022-05-30]
SELECT PDate, ItemName, MPQty, PQty, ISNULL(SQty,0) AS SQty, ISNULL((CASE WHEN SQTY>=PQty THEN 0 WHEN (SQty+MPQty)>PQty THEN PQty-SQty ELSE MPQty END),0) AS Qty, Rate, (ISNULL((CASE WHEN SQTY>=PQty THEN 0 WHEN (SQty+MPQty)>PQty THEN PQty-SQty ELSE MPQty EN ... -
根据你的jsfiddle,你没有在表#quandatbl中输入。 尝试更改功能 function calculateTotal() { var totalweight = totalmarks; $("#qandatbl_onthefly_container td.weight input").each(function (i, elm){ totalweight = totalweight - Number($(elm).val(), 10); }); $(" ...
-
收集/选择行进行计算(Gather/Select rows for calculation)[2022-07-04]
假设您的表按日期排序(它在图片中),那么可以使用VLOOKUP解决第一个问题 =VLOOKUP("1",A1:C6,3,0) 将"1"替换为新表中包含ID 1单元格。 对于问题2,您可以使用以下公式,再次使用新表中包含ID 1单元格替换=1 {=MEDIAN(IF(A1:A6=1,C1:C6,""))} 注意,这是一个数组公式,你不直接键入大括号{} ,但只需按CTRL + SHIFT + ENTER ,而不是输入公式时只需输入 这可以通过创建像这样的数组{12,23,"","",""}并取这些数字的中 ... -
沿行传播计算(Propagating calculation along rows)[2023-10-30]
这是基础R中相当简单的方法。 with(df, cumsum(x + ifelse(is.na(ed0), 0, ed0) + c(0, head(kd, -1)))) [1] 0.2432977 30.2080240 70.1648789 为了解决这个问题,x保持原样并且c(0, head(kd, -1))设置kd的滞后向量,其中初始值为0. ifelse(is.na(ed0), 0, ed0)检查如果ed0的每个元素都是NA,如果为TRUE则将其替换为0。 将这三个术语相加在一起,并将得到的矢量给予 ... -
你不能在计算时使用别名 select invoice_ no, exe_amount, exe_amount*0.02 as edu_duty, exe_amount*0.01 as ed_duty, (exe_amount + (exe_amount*0.02) + (exe_amount*0.01)) as sub_total, ((exe_amount + (exe_amount*0.02) + (exe_amount*0.0 ...