reactjs - React Js解析错误:严格模式下不允许遗留八进制文字
问题描述
我是 React Js 的新手,我有一个表单,我从用户那里得到一个字符串,我把这个字符串分成空格,然后我把它保存在我的状态变量中,这段代码工作正常:
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();
}
然后我只是尝试添加变量以在数组中推送数据(如果它不存在“smth”),但出现此错误:解析错误:在严格模式下不允许传统八进制文字。
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();
}
所以第一个代码工作正常,但它没有添加不匹配的字符串,这就是我想要添加的,希望我能得到一些帮助。谢谢你。
解决方案
推荐阅读
- kubernetes - 在没有 vm(单节点)的本地系统中运行 k8s 的选项
- sapui5 - 如何使用 sap.ui.Table 创建第一列固定的表
- django - Django:过滤和编辑对象的model_set并以一对多关系返回该对象的查询集
- pyspark - 在 pyspark (databricks) 中使用来自 NLTK 的停用词时出现酸洗错误
- django - 使用外键的 Django 信号 post_save
- java - 如何比较两个哈希图/哈希表以仅找到唯一键
- python-3.x - 设备的序列号是否唯一?
- generics - Nim 中的 any 类型的混淆问题
- c# - 单元测试起订量通用类型
- java - 在我的程序中使用 break 语句使用 switch 语句计算闰年的问题