簡體   English   中英

流星JS錯誤; 意外標記 ',' 應為 '['

[英]Meteor JS error; Unexpected token ',' expected '['

我對使用meteor JS 還很陌生,在嘗試向電子郵件模板提供mongo 記錄時遇到了這個模糊的錯誤。 這是收到的 exc 錯誤

`阻止啟動的錯誤:

使用 ecmascript 處理文件時(針對目標 os.osx.x86_64):server/main.js:22:75: Unexpected token, expected ] (22:75)

您的應用程序有錯誤。 等待文件更改。`

提供了一個代碼片段來顯示我的服務器文件的樣子。

 import { Meteor } from 'meteor/meteor'; import { Mongo } from 'meteor/mongo' Meteor.startup(() => { // code to run on server at startup var smtp = { username: 'nayyir.-----@----.com', password: '-----------------', server: '----.-----.com', port: --- } var vehicle = Mongo.collections('vehicles').findOne(); var specifications = []; var user = Mongo.collections('users').findOne(); process.env.MAIL_URL = 'smtps://' + encodeURIComponent(smtp.username) + ':' + encodeURIComponent(smtp.password) + '@' + encodeURIComponent(smtp.server) + ':' + smtp.port; Meteor.methods({ sendEmail: function() { console.log('on server - sending email'); SSR.compileTemplate('htmlEmail', Assets.getText('mitsubishi-email.html')); for (var i in vehicle['specifications']){ var spec = Mongo.collections('specattributes').find('_id': vehicle['specifications'][i]['attr_id']); var specattributes = {}; specattributes['spec_value'] = vehicle['specifications'][i].val.en; specattributes['spec_category'] = spec; specifications.push(specattributes); } var emailOptions = { firstname: user.firstname, lastname: user.lastname, specifications = specifications, improvements = vehicle.improvements, reasons = vehicle.reasonsToBuy } Email.send({ to: '------@------.com', from: '------@------.com', subject: 'Test', html: SSR.render('htmlEmail', emailOptions), }); console.log('on server - sent email'); } }) });

非常感謝任何幫助!

TIA

該錯誤表明第 22 行存在問題,如下所示:

var spec = Mongo.collections('specattributes').find('_id': vehicle['specifications'][i]['attr_id']);

我想你忘記了花括號,所以它應該是這樣的:

var spec = Mongo.collections('specattributes').find({'_id': vehicle['specifications'][i]['attr_id']});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM