2015-08-09 15 views
5

Sto facendo un Meteor.call('searchDatabase', keys...) che viene eseguito ogni volta che un utente invia una ricerca. Attualmente sto passando una serie di parole inviate chiamate keys. Tuttavia, non so come fare il necessario check(keys, ?) sul lato server. Originariamente pensavo di poter fare keys.forEach(function(element) { check(element, String)}, ma ottengo ancora un errore Did not check() all arguments. Dovrei semplicemente passare la ricerca inviata come stringa originale nella chiamata al metodo Meteor e poi romperla sul server? o c'è un modo per verificare che le chiavi siano un array?Parametro array controllo Meteor.call

risposta

13

Se keys è un array di stringhe, si può semplicemente fare:

check(keys, [String]); 

Il tuo metodo sarebbe simile:

Meteor.methods({ 
    searchDatabase: function(keys) { 
    check(keys, [String]); 
    // add other method code here 
    } 
}) 
+0

Sì questo è quello che stavo cercando! Grazie! – thegreenfrog

0

Come mostrato qui: 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; 
})); 
Problemi correlati