如何让条码扫描仪从数据库中检查条码编号?

how to make barcode scanner check for barcode number from database?

有没有办法让条码扫描器检查本地数据库中的条码编号?我一直在尝试在 google 上进行一些搜索,但没有此类内容的教程。


import DataBase from '../Data/DataBase';

class BarCodeReader extends Component {
  constructor(props) {
    super(props);
    this.camera = null;
    this.barcodeCodes = [];

    this.state = {
      camera: {
        type: RNCamera.Constants.Type.back,
        flashMode: RNCamera.Constants.FlashMode.auto,
      },
    };
  }

  onBarCodeRead(scanResult) {
    if (scanResult.data != null) {
      if (!this.barcodeCodes.includes(scanResult.data)) {
        this.barcodeCodes.push(scanResult.data);
        alert(scanResult.data);
      }
    }
    return;
  }

  render() {
    return (
      <View style={styles.container}>
        <RNCamera
          ref={(ref) => {
            this.camera = ref;
          }}}
          onBarCodeRead={this.onBarCodeRead.bind(this)}
        />
      </View>
    );
  }
}

const DataBase = [
  {
    name: 'text',
    company: 'text',
    extra: '7 310350 118670',
  },
];
export default DataBase;
import codes from '../Data/codes';

class BarCodeReader extends Component {
  constructor(props) {
    super(props);
    this.camera = null;
    this.barcodeCodes = [];

    this.state = {
      camera: {
        type: RNCamera.Constants.Type.back,
        flashMode: RNCamera.Constants.FlashMode.auto,
      },
    };
  }
  
  validateCode(scanResult){
    const codeData = codes.find(codeMetadata => {
       return codeMetadata.id === scanResult.data 
    })
    
    if(codeData){
      alert("code valid" + codeData)
    } else {
      alert("code not found")
    }
  }

  onBarCodeRead(scanResult) {
    if (scanResult.data != null) {
      if (!this.barcodeCodes.includes(scanResult.data)) {
        this.barcodeCodes.push(scanResult);
        this.validateCode(scanResult)
      }
    }
    return;
  }

  render() {
    return (
      <View style={styles.container}>
        <RNCamera
          ref={(ref) => {
            this.camera = ref;
          }}}
          onBarCodeRead={this.onBarCodeRead.bind(this)}
        />
      </View>
    );
  }
}

const codes = [
  {
    id: "code-id-text"
    name: 'text',
    company: 'text',
    extra: '7 310350 118670',
  },