@sunnyj58 wrote:
I am trying to build an app that will allow a user to scan a barcode, then save the time this barcode was scanned to native storage.
Then each time the user uses the application, they can continue to add successful scans (times) to native storage.I have found that when I just set a date, it overwrites the previous date. So what I thought to do is take the existing date(s), add them to an array, add the new date to this array then put all this back into native storage.
However what I find is that when the user changes page, then returns to the scan page and adds a date to the array, its adding an entire new array into the old array as one variable rather than separate entries to this array.How can I resolve this?
My code is -
export class ScanSession {emptyArray = [];
ionViewDidEnter(){
this.nativeStorage.getItem(‘scans’)
.then(
data => this.emptyArray.push(JSON.parse(data)),
)
console.log(“Saved Scan Data Loaded”)
}constructor(private barcodeScanner: BarcodeScanner, private nativeStorage: NativeStorage) {
}//Test to see if data is being saved ShowDataTest(): any{ this.nativeStorage.getItem('scans') .then( data => console.log(data) ) }
ScanCode() : any{
this.barcodeScanner.scan().then((barcodeData) => {
let inputString = “testData”;if( barcodeData.text == inputString){ this.emptyArray.push(Date()); this.nativeStorage.setItem('scans', JSON.stringify(this.emptyArray)) console.log("Scan successfully added") } else { console.log("Doesnt Match"); }
}, (err) => {
});
};
}
Posts: 1
Participants: 1