J'essaie de sélectionner tous les enregistrements de table appelé Faircustomer où Business_Type_ID Équipez-vous égal de valeur. J'utilise Sailsjs pour serveur et mySQL pour dB, dans Frontend, j'utilise Nationticscript avec TypeScript.
Mon code: P>
P>
filterShopType(){ this.service.serviceName = 'fairCustomers'; this.service.Get({ populate:'country_id,business_type_id',where:{ business_type_id:{ in:this.business_ids_filter } }, limit:20 }).then((data: any) => { this.fairCustomers.splice(0, this.fairCustomers.length); this.fairCustomers.push(data); this.Refresh('fairCustomers'); }).catch((err) => { console.log('failed get fairCustomers from server ', err); }); }
3 Réponses :
Vous pouvez essayer avec une requête native comme décrit ici, https://sailsjs.com/documentation/reference/waterline-orme/dataSores/send-native-Query P>
Autant que je puisse dire, vous pouvez simplement fournir un tableau d'articles. Les correspondances contre l'un des éléments de la matrice signifie que l'enregistrement doit être renvoyé dans le résultat. Je ne sais pas si cela fonctionne dans un où code> est cependant.
Cela fonctionne avec moi en utilisant [ou] au lieu de [in], il s'agit du code
p>
filterShopType(){ if(this.business_ids_filter){ this.service.serviceName = 'fairCustomers'; var arr = []; this.business_ids_filter.forEach( (id) => { arr.push({ business_type_id: id }) }); let where = {}; if(arr.length > 0){ where = {or: arr}; } this.service.Get({ populate: 'country_id,business_type_id',where:where , limit:20 }).then((data: any) => { this.filterItems.splice(0, this.filterItems.length); this.filterItems.push(data); this.Refresh('filterItems'); }).catch((err) => { console.log('failed get fair Customers from server ', err); }); }else{ this.set('isFilter', false); } }