Я новичок в метеор, и я следую первому учебнику (TODO LIST), но используя его собственный пример. Итак, я смог отправить форму в БД mongo, но не уверен, через шаблон клиента. Теперь я двигаюсь, чтобы определить метод на файл, который может быть использован как для клиента и сервера, используя этот код - cliente.js:Использование Meteor.call для вставки нескольких полей, выпуск
import { Meteor } from 'meteor/meteor';
import {Mongo} from 'meteor/mongo';
import { check } from 'meteor/check';
export const Clientes = new Mongo.Collection('clientes');
Meteor.methods({
'clientes.insert'(nome, idade,genero,sessao,data,quemPreenche) {
check(nome, String);
check(idade, String);
check(genero, String);
check(sessao, String);
check(data, Date);
check(quemPreenche, String);
// Make sure the user is logged in before inserting a task
if (! this.userId) {
throw new Meteor.Error('not-authorized');
}
Clientes.insert({
nome,
idade,
genero,
sessao,
data,
quemPreenche,
createdAt: new Date(),
owner: this.userId,
username: Meteor.users.findOne(this.userId).username,
});
},
});
А на стороне клиента, я звоню метод, как это - novasessao.js:
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
import { Perguntas } from '../api/perguntas.js';
import { Clientes } from '../api/clientes.js';
import './novasessao.html';
Template.novasessao.events({
'keypress form.nova-sessao' : function (event){
if (event.which === 13) {
event.preventDefault();
let dadosclientes = {};
const target = event.currentTarget;
const nome = target.nome.value;
const idade = target.idade.value;
const genero = target.genero.value;
const sessao = target.sessao.value;
const data = target.data.value;
const quemPreenche = target.quemPreenche.value;
Meteor.call('clientes.insert',{nome,idade,genero,sessao,data,quemPreenche});
}
}
});
проблема заключается в том, что я не могу представить больше получаю следующее сообщение об ошибке:
Exception while simulating the effect of invoking 'clientes.insert' errorClass {message: "Match error: Expected string, got object", path: "", sanitizedError: errorClass, errorType: "Match.Error", stack: "Error↵ at exports.check (http://localhost:3000/…983d07ae9423dd57f5b3c9f92b5593d2952f1b86:3717:25)"} Error
at exports.check (http://localhost:3000/packages/check.js?hash=63d7478b74cadc04d378bc2266ea8bd1bf6849d8:67:15)
at DDPCommon.MethodInvocation.clientesInsert (http://localhost:3000/app/app.js?hash=cfb80c1b0d41ad6244ac6e6510745a82024f58f6:200:7)
at http://localhost:3000/packages/ddp-client.js?hash=bc32a166cd269e06a394f9418e0024d805bab379:3973:25
at Meteor.EnvironmentVariable.withValue (http://localhost:3000/packages/meteor.js?hash=e3f53db3be730057fed1a5f709ecd5fc7cae1229:1077:17)
at Connection.apply (http://localhost:3000/packages/ddp-client.js?hash=bc32a166cd269e06a394f9418e0024d805bab379:3964:54)
at Connection.call (http://localhost:3000/packages/ddp-client.js?hash=bc32a166cd269e06a394f9418e0024d805bab379:3840:17)
at Object.keypressFormNovaSessao (http://localhost:3000/app/app.js?hash=cfb80c1b0d41ad6244ac6e6510745a82024f58f6:139:40)
at http://localhost:3000/packages/blaze.js?hash=983d07ae9423dd57f5b3c9f92b5593d2952f1b86:3718:20
at Function.Template._withTemplateInstanceFunc (http://localhost:3000/packages/blaze.js?hash=983d07ae9423dd57f5b3c9f92b5593d2952f1b86:3687:12)
at Blaze.View.<anonymous> (http://localhost:3000/packages/blaze.js?hash=983d07ae9423dd57f5b3c9f92b5593d2952f1b86:3717:25)
meteor.js?hash=e3f53db…:930 Error invoking Method 'clientes.insert': Match failed [400]
может кто-нибудь помочь здесь?
Спасибо!
Hi Миккель, tahnk вас. Я заменил, но теперь я получаю эту ошибку: 'novasessao.js: 16 Uncaught ReferenceError: target не определен at Object.keypressFormNovaSessao (novasessao.js: 16)'. На самом деле я не понял, почему вы заменили const target = event.currentTarget; для цели: event.currentTarget; – EFO
Извините, мой плохой, вы правы, используйте const target = event.currentTarget; – Mikkel
Нет проблем, но затем это еще одна ошибка: «Исключение при имитации эффекта вызова« clientes.insert »errorClass {сообщение:« Ошибка совпадения: ожидаемая дата », путь:« », sanitizedError: errorClass, errorType:« Match. Error ", stack:" Error↵ at export.check (http: // localhost: 3000/... 983d07ae9423dd57f5b3c9f92b5593d2952f1b86: 3717: 25) "} Error ...' ' – EFO