【发布时间】:2019-09-06 02:08:44
【问题描述】:
我需要为已定义参数的道具声明一个函数。该组件是来自 react-native-collapsible 的 Accordion。我要实现功能的组件的 prop 是 onChange(indexes),我想为它传递一个附加参数'title'。
我尝试传递同名“indexes”的参数,但尚未声明变量“indexes”,因此在执行时返回错误。我不知道传递新参数的语法是什么。
将函数传递给没有任何参数的道具就可以了,但是我需要将标题作为参数传递给函数。
组件本身(我希望 onChange 道具调用带有活动手风琴索引和标题的 updateSections):
<Accordion
sections={data}
activeSections={activeSections}
renderHeader={this.renderHeader}
renderContent={this.renderList}
onChange={this.updateSections(indexes, title)}
touchableComponent={TouchableOpacity}
/>
这很好用:
<Accordion
sections={data}
activeSections={activeSections}
renderHeader={this.renderHeader}
renderContent={this.renderList}
onChange={this.updateSections}
touchableComponent={TouchableOpacity}
/>
要实现的功能:
updateSections = (activeSections, title) => {
switch (title) {
case 'PA':
this.setState({ activeSectionsPA: activeSections });
break;
case 'CA':
this.setState({ activeSectionsCA: activeSections });
break;
default:
break;
}
}
任何帮助将不胜感激!谢谢!
【问题讨论】:
标签: javascript react-native jsx react-native-collapsible