0
在reactjs中,我們將更改節點委託給渲染方法,一旦完成修改,我們如何調用或獲取像selectedIndex
這樣的屬性?我選擇selectedIndex
,因爲即使用戶沒有真正選擇任何東西,它也是0。如何在render()中調用.selectedIndex?
例如:
render() {
<CategoryInput
categories={this.state.categories}
onValueChange={function(event) {
// not called when options themselves have changed
}}
ref={(input) => {
if (input) {
// the is a reference to the instance
}
}}
/>
// now that the categories have been added to the component
// I'd like to retrieve selectedIndex to use on a sibling's component
}
我擔心的是我沒有從節點本身獲取selectedIndex,而是我假設它會是什麼。這是保證在規範?在reactjs之外,我只使用本地DOM過程。 – chrisp
https://facebook.github.io/react/docs/forms.html#why-select-value這將通過處理選擇的React方式。它使用選擇的值來確定一切。您不必擔心selectedIndex,只需確保該值與您在下拉菜單中輸入的值相匹配 – finalfreq
謝謝。這已經足夠了。 (感謝鏈接到文章我必須讀其他原因一百萬次 - 錯過了選擇部分) – chrisp