i'am new to React Js , i have a form where i get a string from the user, i split this string into spaces , then i save it in my state variable this code works fine :
handleSubmit(event) {
event.preventDefault();
let products = this.state.newProducts;
//split the string into an array
var string = this.state.QrCode.split(" ");
// check all the string in the form if the Qr match an exsitant => save it
for(var i =0; i < string.length; i++){ // fetch the entery
this.state.smth.map(prd => { // fetch the database
if(prd.Qr==string[i]){ // verification
products.push({
id: prd.id,
Qr: prd.Qr,
Stat: prd.Stat,
name: prd.name
});
}
}
)
}
// save it in newProducts
this.setState({
newProducts: products
});
// refresh the grid
this.grid.refresh();
}
then i simply tried to add variable to push a data in the array if it doest exist "smth" , but am getting this error : Parsing error: Legacy octal literals are not allowed in strict mode.
handleSubmit(event) {
event.preventDefault();
let hasChanged = 0;
let products = this.state.newProducts;
//split the string into an array
var string = this.state.QrCode.split(" ");
// check all the string in the form if the Qr match an exsitant => save it
for(var i =0; i < string.length; i++){ // fetch the entery
this.state.smth.map(prd => { // fetch the database
if(prd.Qr==string[i]){ // verification
hasChanged=1;
products.push({
id: prd.id,
Qr: prd.Qr,
Stat: prd.Stat,
name: prd.name
});
}
if(hasChanged==0){
products.push({
id: 00,
Qr: string[i],
Stat: "unknown",
name: "XXXX"
});
}
}
)
}
// save it in newProducts
this.setState({
newProducts: products
});
// refresh the grid
this.grid.refresh();
}
so the 1st code works fine , but it doest add the no matching string and thats what i want to add hope i can get some help . thank you.