【问题标题】:Check Arguments on Meteor.call(...)检查 Meteor.call(...) 上的参数
【发布时间】:2015-01-04 01:11:25
【问题描述】:

#Meteor v. 1.0# Meteor.call(title, description) 抛出异常

检查客户端的参数:

'click div[name="saveCollection"]' : function(e) {
    var title = 'Title'
    var description = 'Description'

    check(title, String) 
    check(description, String)

    Match.test(title, String)        --> It's true    
    Match.test(description, String)  --> It's also true 

    Meteor.call('saveCollection', title, description, function(error, result){
    ...
    })
}

检查服务器上的参数:

saveCollection: function (title, description) {
    check(title, String)
    check(description, String)

    Match.test(title, String)        --> It's true  
    Match.test(description, String)  --> It's also true  

    Collection.insert({
       title: title,
       description: description
   })
}
调用方法“saveCollection”时出现异常错误:在调用“saveCollection”期间未检查()所有参数

我做错了什么??

【问题讨论】:

  • @Kyll,检查客户端的参数(两次)既不正常也没有必要。
  • @j03I 这是代码库中唯一调用saveCollection 的实例吗?
  • 也许有一种变通方法会奏效。在服务器代码上,不是用titledescription调用check(),你能不能分别用arguments[0]arguments[1]替换它们?
  • 我已经替换了参数,但问题仍然存在。我会继续努力:)

标签: meteor


【解决方案1】:

正如cmets所说,你不是要打电话吗

Meteor.call('saveCollection', title, description)

而不是

Meteor.call('saveCollection', description, description)

这可能会弄乱审计参数检查。

【讨论】:

  • 哦,那我错过了理解 Kylls 的评论。但是,您的建议应该没有什么区别,因为两个参数都是字符串。
  • 在我输入问题时出现了一些问题。在我的代码中,我写道: Meteor.call('saveCollection', title, description)。问题依然存在。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-07
  • 2016-10-02
  • 1970-01-01
相关资源
最近更新 更多