我在数组中存储了一些数据。 这将是这样的
datas[
password:"dfsdfsd",
username : "dfgdgdfg55555",
password:"deep",
username : "dfgdgdfg56556",
password:"hello",
username : "dfgdgdfg65",
password:"hello1234",
username : "dfgdgdfg123"
]
现在我想用camapare用户名。 而我正在尝试它,并希望如果条件为真(带我到另一页)但不知道该怎么做。
checkCred(){
var details_array = this.state.datas1 ;
console.log(details_array);
for(var i=0; i < details_array.length; i++) {
var currentObject = details_array[i];
if (this.email.value === currentObject.username) {
console.log('yes done it');
window.location = '/Index';// this is not working and think window.location is stupid methed...
// please guide me if you have any better idea than this
}
}
}
<input ref={(e) => this.email = e} name="email" type="email" /><br/>
我做得对吗?
答案 0 :(得分:2)
按照预期进行以下更改
var details_array = this.state.datas ;
for(var i=0; i < details_array.length; i++){
var currentObject = details_array[i];
if (this.email.value === currentObject.username){
console.log('yes done');
}
}
注意:希望您在details_array中有数据。