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