this.state.hiring.map(h => (
<FormApp
condType={h.type}
condRef={h.ref}
label={h.name}
labelName={h.name}
name={h.id}
id={h.name}
validations={h.required == true ? [this.required] : null}
dataList={this.state[h.ref]}
onChange={this.onChangeInput}
/>
));
我想
if (h.requered == true) { return [this.required] } else { null }
我有问题
react js: TypeError:对象null不可迭代(无法读取属性Symbol(Symbol.iterator)属性)
答案 0 :(得分:1)
也许您可以像这样修改代码:
const { hiring } = this.state;
hiring instanceof Array && hiring.map(h => { // ==> Validate hiring before use it.
if (h.requered == true) {
return (
<FormApp
condType={h.type}
condRef={h.ref}
label={h.name}
labelName={h.name}
name={h.id}
id={h.name}
validations={h.required == true ? [this.required] : null}
dataList={this.state[h.ref]}
onChange={this.onChangeInput}
/>
);
} else {
return null;
}
});