我有一个箭头功能,可以将表单字段的验证显示为:
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <ctime>
using namespace std;
void computerPick(char soccer[][3]);
void shot(char shooter[][3], int userInputY, int userInputX);
int main()
{
int userInputX;
int userInputY;
srand(time(NULL));
char soccer[2][3];
for(int i=0; i<2; i++)
{
for(int j=0; j<3; j++)
{
soccer[i][j]='-';
}
}
cout<<"Pick a X coordinate to shoot at: "<<endl;
cin>>userInputX;
cout<<"Pick a Y coordinate to shoot at: "<<endl;
cin>>userInputY;
computerPick(soccer);
shot(soccer,userInputY,userInputX);
}
void computerPick(char soccer[][3])
{
int x = rand()%3;
int y = rand()%2;
soccer[x][y]='B';
}
void shot(char shooter[][3], int userInputY, int userInputX)
{
int score=0;
if(shooter[userInputX][userInputY]!='B')
cout<<"shot is good"<<endl;
else
cout<<"shot is blocked"<<endl;
}
现在我想从另一个循环遍历所有表单条目的函数调用函数:
showValidation = (field) => () => {
console.log(field);
this.setFieldState(field, {showValidation: true});
}
showAllValidations() {
let self = this;
for (let field of ['a', 'b', 'c', 'd', 'e', 'f', 'g']) {
console.log(field);
self.showValidation(field);
}
}
中的console.log(field)
在showValidation
console.log(field)
显示所有字段时不会打印任何内容,所以我认为它没有被调用。我是ReactJs&amp;的新手ES6并长期坚持这个问题。