我正在执行Meteor.call('searchDatabase', keys...)
,只要用户提交搜索就会执行该keys
。我目前正在传递一系列名为check(keys, ?)
的提交词。但是,我不知道如何在服务器端执行必要的keys.forEach(function(element) { check(element, String)}
。我原本以为我可以Did not check() all arguments
,但我仍然会收到<?php
$i=0;
$count=0;
foreach ($_FILES['file']['name'] as $filename)
{
$upload_dir = $_SERVER['DOCUMENT_ROOT'] . "/upload/";
if(file_exists($upload_dir.$filename))
{
echo "That File Already Exist";
break;
}
else
{
$tmp = $_FILES['file']['tmp_name'][$count];
$count++;
$i++;
$target = $upload_dir.basename($filename);
if (is_dir($upload_dir) && is_writable($upload_dir)) {
move_uploaded_file($tmp,$target);
$sql = "UPDATE `fleet` SET `image$i`='$target',`image_name$i`='$filename' WHERE id='$id' ";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
} else {
echo 'Upload directory is not writable, or does not exist.';
}
}
错误。我应该在Meteor方法调用中将提交的搜索作为其原始字符串传递,然后在服务器上将其分解吗?或者有办法检查键是否为数组?
答案 0 :(得分:15)
如果keys
是一个字符串数组,您可以这样做:
check(keys, [String]);
您的方法看起来像:
Meteor.methods({
searchDatabase: function(keys) {
check(keys, [String]);
// add other method code here
}
})
答案 1 :(得分:0)
如下所示: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;
}));
答案 2 :(得分:0)
如果您使用simple-schema,则应尝试以下方式:
check( keys, [ mySchema ] );
您可以在此链接中了解有关检查模式的更多信息 using-the-check-package
答案 3 :(得分:0)
万一它对其他人有帮助,我将Meteor forums的答案改写为使用箭头函数,并避免使用下划线和重复声明:
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;
}));
这将检查对象数组。