这是一个调用服务器端方法的按钮单击事件:
Template.newTeam.events
"click .btn-save": ->
form={}
$.each $('#newTeamForm').serializeArray(), ->
form[this.name] = this.value;
Meteor.call 'saveTeam', form, (error, result) ->
if error.error == "team-exists"
alert "A Team with this name already exists."
else
console.log 'saved'
Router.go('list-teams')
单击btn-save时,将显示以下错误
是Meteor.call不接受对象或数组作为参数。我可以用分离的参数调用该方法,但我想知道是否可以发送和数组或对象。
[Log] Exception in delivering result of invoking 'saveTeam': http://localhost:3000/client/views/dashboard/teams/teams.coffee.js?ace17a4ab13667bbc2fa272b80dc3018fb860a52:10:16 (meteor.js, line 883)
http://localhost:3000/packages/meteor.js?61916b1060b33931a21f104fbffb67c2f3d493c5:973:27
_maybeInvokeCallback@http://localhost:3000/packages/ddp.js?1f971b2ac9f4bdab7372cb5098ed1e26ff98dfb2:3853:21
receiveResult@http://localhost:3000/packages/ddp.js?1f971b2ac9f4bdab7372cb5098ed1e26ff98dfb2:3873:30
_livedata_result@http://localhost:3000/packages/ddp.js?1f971b2ac9f4bdab7372cb5098ed1e26ff98dfb2:4926:22
onMessage@http://localhost:3000/packages/ddp.js?1f971b2ac9f4bdab7372cb5098ed1e26ff98dfb2:3718:28
http://localhost:3000/packages/ddp.js?1f971b2ac9f4bdab7372cb5098ed1e26ff98dfb2:2713:19
forEach@[native code]
forEach@http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:156:18
onmessage@http://localhost:3000/packages/ddp.js?1f971b2ac9f4bdab7372cb5098ed1e26ff98dfb2:2712:15
dispatchEvent@http://localhost:3000/packages/ddp.js?1f971b2ac9f4bdab7372cb5098ed1e26ff98dfb2:152:27
_dispatchMessage@http://localhost:3000/packages/ddp.js?1f971b2ac9f4bdab7372cb5098ed1e26ff98dfb2:1137:23
_didMessage@http://localhost:3000/packages/ddp.js?1f971b2ac9f4bdab7372cb5098ed1e26ff98dfb2:1195:34
onmessage@http://localhost:3000/packages/ddp.js?1f971b2ac9f4bdab7372cb5098ed1e26ff98dfb2:1342:28
帮助将非常感激。
编辑:
这是saveTeam方法。数据成功传递给此方法。但我仍然看到了这个错误。
Teams = new Mongo.Collection('teams');
Meteor.methods
saveTeam: (team) ->
if ! this.userId
throw new Meteor.Error("not-logged-in", "Must be logged in to post a comment.")
if Teams.findOne({name: team.name})
throw new Meteor.Error("team-exists", "A team with this name already exists.")
else
Teams.insert
createdBy: Meteor.userId(),
name: team.name,
description: team.description,
visibility: team.visibility