最佳答案
新的反应和尝试循环对象属性,但反应抱怨对象不是有效的反应孩子,可以有人给我一些建议,如何解决这个问题?我已经添加了 createFragment,但是不完全确定需要把它放在哪里,或者应该采取什么方法?
JS
var tifs = {1: 'Joe', 2: 'Jane'};
var tifOptions = Object.keys(tifs).forEach(function(key) {
return <option value={key}>{tifs[key]}</option>
});
渲染功能
render() {
const model = this.props.model;
let tifOptions = {};
if(model.get('tifs')) {
tifOptions = Object.keys(this.props.model.get('tifs')).forEach(function(key) {
return <option value={key}>{this.props.model.get('tifs')[key]}</option>
});
}
return (
<div class={cellClasses}>
<div class="grid__col-5 text--center grid__col--bleed">
<h5 class="flush text--uppercase">TIF</h5>
<select id="tif" name="tif" onChange={this.handleChange}>
{tifOptions}
</select>
</div>
</div>
);
}
控制台错误
If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object)