我使用react-select,想循环内循环来代表它作为选择的值和标签:通过对象的数组对象
// Inside the component's render:
var myVar = [
this.props.foo.forEach(function(a){
{value: a.name, label: a.name} // line 83
})
];
//return
<Select ref="stateSelect" options={myVar} simpleValue clearable={this.state.clearable}
name=""
value={this.state.bar} onChange={this._myFunc}
/>
this._myFunc
是不相关的这个问题。我想是这样的:
var myVar = [
{value: "hello", label: "world"},
// the list goes on
];
与上面的代码,我有:
Parse Error: Line 83: Unexpected token :
我不是的JavaScript强烈找出这种解决方案,但是这可能吗?链接阅读?
'{...}'是在这里被认为是** block **。可能你需要'someObj = {value:a.name,label:a.name}' – Tushar