当用户提交搜索时,我正在执行一个Meteor.call('searchDatabase', keys...)。我目前正在传递一个名为keys的单词数组。但是,我不知道如何在服务器端执行必要的check(keys, ?)。我最初以为我可以做keys.forEach(function(element) { check(element, String)},但是我仍然得到了一个Did not check() all arguments错误。我是否应该将提交的搜索作为Meteor方法调用中的原始字符串传递,然后在服务器上将其拆分?还是有一种方法来检查键是否是数组?
发布于 2015-08-09 17:28:54
如果keys是一个字符串数组,您可以这样做:
check(keys, [String]);您的方法应该类似于:
Meteor.methods({
searchDatabase: function(keys) {
check(keys, [String]);
// add other method code here
}
})发布于 2019-12-05 09:44:28
如果它对其他人有帮助,我将流星论坛的答案重铸为使用箭头函数,并避免下划线和重复声明:
check(subscriptions, Match.Where((myArray) => {
myArray.forEach((myObject) => {
/* do your checks and return false if there is a problem */
});
// return true if there is no problem
return true;
}));这将检查一个对象数组。
发布于 2015-08-09 17:23:43
如下图所示:https://forums.meteor.com/t/check-object-in-an-array/3355
var subscriptions = [
{/* ... */},
{/* ... */},
{/* ... */}
];
check(subscriptions, Match.Where(function(subscriptions){
_.each(subscriptions, function (doc) {
/* do your checks and return false if there is a problem */
});
// return true if there is no problem
return true;
}));https://stackoverflow.com/questions/31906804
复制相似问题