我使用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