這裏是我的<select>
組件:如何通過React <select>組件傳遞多個參數?
handleSelect: function(myVar, anotherVar) {
// Do I need to somehow use event.preventDefault(); here?
// I want to be able to do something with myVar and anotherVar here...
// ...but it seems I cannot access the event and the value of anotherVar
// at the same time...at least not this way.
},
render: function() {
let myVar = "Yes",
anotherVar = "Another value",
id = 1;
return (
<select defaultValue={myvar} onChange={this.handleChange.bind(this, anotherVar}>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
);
}
我希望能夠在我的handleSelect
功能與myVar
(基於<select>
輸入的值)anotherVar
工作。在這種情況下,我該如何正確傳遞<select>
元素的值?