let cc = "";
let allCourse = ['C#', 'C++', 'Java', 'Python'];
if (this.state.courses.length > 0) {
allCourse.map(cr => {
cc = this.state.courses.map((c, index) => {
if (cr !== c) {
return (
<option value={cr} key={index} onClick={this.handleChange}>{cr}</option>
)
}
})
})
}
我要打印this.state.courses中的项目以外的项目。但是如果this.state.courses等于'java'上面的代码仅显示Python
我想你想要这个:
let allCourse = ['C#', 'C++', 'Java', 'Python'];
if (this.state.courses.length > 0) {
allCourse.map(cr => {
return this.state.courses.indexOf(cr) === -1 && (
<option value={cr} key={index} onClick={this.handleChange}>{cr}</option>
)
})
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句