【问题标题】:Find coincidence between item in Firebase List and value provided查找 Firebase 列表中的项目与提供的值之间的重合
【发布时间】:2017-06-06 20:45:41
【问题描述】:

对不起,我的问题。也许这太明显了,但我是 Ionic 的新手,我希望尽可能做到最好。

我有一个条形码扫描仪,它返回一个带有我的 firebase 数据库中集合键的值。我需要知道扫描的代码是否存在于我的数据库中。到目前为止,这就是我所拥有的:

export class HomePage {

    constructor(
         private barcode: BarcodeScanner, 
         public navCtrl: NavController, 
         af: AngularFireDatabase) {

         // Here I get the list of elements where I will search the scanned code.
         this.ocupadas = af.list('/UbicacionesOcupadas', { 
             query: { 
                 orderByChild: 'evento', 
                 equalTo: 28 
             }
         });
      }

      // Here I get the QR Code value.
      async scanBarcode() {
          this.results = await this.barcode.scan(this.options);
      }

      // Now, I need to know if the QR Code value is in the firebase list. How would you do?

【问题讨论】:

标签: angular firebase firebase-realtime-database ionic2


【解决方案1】:

您可以尝试使用find 来比较结果。

public findScanAgainstStoredList(scannedItem){
   // scannedItem being this.results
   let item = this.ocupadas.find(scannedItem);
   if(item != undefined){
       // do something if there is an item
   }else{
       // do something if no item is found
   }
}

【讨论】:

  • 感谢@gerdi 的贡献。我尝试使用查找,但 Visual Studio 代码返回错误:类型 'FirebaseListObservable' 上不存在属性 'find'
猜你喜欢
  • 1970-01-01
  • 2021-09-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多