我是Meteor Javascript的初学者。我正在尝试发送邮件数组结果。我的代码如下
var Testname = test.find({}).fetch();
var a = [];
var b = [];
var c = [];
var allResult = [];
_.each(Testname, function(testname){
var testResult = test.findOne({_id:testname._id});
var st = testResult.st;
var end_date = testResult.et;
var pt = testResult.percentileCalculationTill;
var br = testAttempts.find({activity_id:testname._id,start_time:{$st, $pt}}).count();
b.push(br);
var Afterresult = testAttempts.find({activity_id:testname._id,start_time:{$pt, $lt:end_date}}).count();
a.push(Afterresult);
var k = testname.name;
c.push(k);
});
var email = {
to: 'xxx.com',
from: 'xxxx.com',
subject: "xxx",
cc: "xxx",
text: "Name: " + c +
"\n\nWith : " + b +
"\n\nAfter: " + a
};
Meteor.call("send_email", email.to, email.from, email.subject, email.cc, email.text);
我的结果是
Name : abs, dfg
With: 4,5
After: 7,6
但我想要如下“
Name : abs With: 4 After: 7
Name : dfg With: 5 After: 6`
那我怎么解决呢。 请尽快给我更新。
答案 0 :(得分:0)
目前,您有三个数组:a,b,c,它们都是相等的长度。您需要循环遍历数组并逐个组合相应的元素。下面的代码不是最好的解决方案(例如,你真的不应该使用a.length来确定a,b,c的长度),但它是最容易理解的方法,应该指向正确的方向。< / p>
var textString = '';
for(var row = 0; row < a.length; row++){
textString = textString + 'Name: ' + c[row] + ' With: ' + b[row] + ' After: ' + a[row] + '\n\n'
}
var email = {
to: 'xxx.com',
from: 'xxxx.com',
subject: "xxx",
cc: "xxx",
text: textString
};