Javascript NativeBase手风琴';s";renderHeader“;显示参数“0”的未定义值的属性;扩大的;
我正在我的一个本地项目中使用本地手风琴。我需要自定义它的标题,为此,我查阅了它的文档。文档中提到的方法无法正常工作。Javascript NativeBase手风琴';s";renderHeader“;显示参数“0”的未定义值的属性;扩大的;,javascript,react-native,native-base,Javascript,React Native,Native Base,我正在我的一个本地项目中使用本地手风琴。我需要自定义它的标题,为此,我查阅了它的文档。文档中提到的方法无法正常工作。\u renderHeader(title,expanded)函数的expanded参数在我检查警报中的值时显示未定义。它应该给我true或false以下是本机基本文档中给出的代码。有谁能指导我如何根据打开和关闭手风琴给我提供true或false import React, { Component } from "react"; import { Container, Header
\u renderHeader(title,expanded)
函数的expanded
参数在我检查警报中的值时显示未定义。它应该给我true
或false
以下是本机基本文档中给出的代码。有谁能指导我如何根据打开和关闭手风琴给我提供true
或false
import React, { Component } from "react";
import { Container, Header, Content, Accordion, View, Text } from "native-base";
const dataArray = [
{ title: "First Element", content: "Lorem ipsum dolor sit amet" },
{ title: "Second Element", content: "Lorem ipsum dolor sit amet" },
{ title: "Third Element", content: "Lorem ipsum dolor sit amet" }
];
export default class AccordionCustomHeaderContentExample extends Component {
_renderHeader(title, expanded) {
return (
<View
style={{ flexDirection: "row", padding: 10, justifyContent: "space-between", alignItems: "center", backgroundColor: "#A9DAD6" }}
>
<Text style={{ fontWeight: "600" }}>
{" "}{title}
</Text>
{expanded
? <Icon style={{ fontSize: 18 }} name="remove-circle" />
: <Icon style={{ fontSize: 18 }} name="add-circle" />}
</View>
);
}
_renderContent(content) {
return (
<Text
style={{ backgroundColor: "#e3f1f1", padding: 10, fontStyle: "italic" }}
>
{content}
</Text>
);
}
render() {
return (
<Container>
<Header />
<Content padder>
<Accordion
dataArray={dataArray}
renderHeader={this._renderHeader}
renderContent={this._renderContent}
/>
</Content>
</Container>
);
}
}
import React,{Component}来自“React”;
从“本机库”导入{容器、标题、内容、手风琴、视图、文本};
常量数据数组=[
{标题:“第一要素”,内容:“Lorem ipsum dolor sit amet”},
{标题:“第二要素”,内容:“Lorem ipsum dolor sit amet”},
{标题:“第三要素”,内容:“Lorem ipsum dolor sit amet”}
];
导出默认类AccordionCustomHeaderContentExample扩展组件{
_renderHeader(标题,展开){
返回(
{“}{title}
{扩展
?
: }
);
}
_renderContent(内容){
返回(
{content}
);
}
render(){
返回(
);
}
}
此问题与参数中存在语法差异的accordion接口有关(即,扩展参数在其代码中丢失)。Native base团队在几天前解决了此问题。因此,您需要删除node_modules文件夹,然后使用以下命令安装插件:npm install native-base --save
react-native link
我认为,这可能是您面临的问题的原因,请查找“renderHeader”旧代码:renderHeader?: (item: any) => React.ReactElement<any>;
renderHeader?:(项:any)=>React.ReactElement
希望这能对您有所帮助。\u renderHeader({title,expanded}){
_renderHeader({title, expanded}) {
return (
<View
style={{ flexDirection: "row", padding: 10, justifyContent: "space-between", alignItems: "center", backgroundColor: "#A9DAD6" }}
>
<Text style={{ fontWeight: "bold", fontSize:20 }}>
{" "}{title}
</Text>
{expanded
? <Icon style={{ fontSize: 18 }} name="remove-circle" />
: <Icon style={{ fontSize: 18 }} name="add-circle" />}
</View>
);
}
_renderContent({content}) {
return (
<Text
style={{ backgroundColor: "#e3f1f1", padding: 10, fontStyle: "italic" }}
>
{content}
</Text>
);
}
返回(
{“}{title}
{扩展
?
: }
);
}
_renderContent({content}){
返回(
{content}
);
}
以下内容对我很有用:
renderHeader({title}) {
return (
<View
style={{ flexDirection: "row", padding: 10, justifyContent: "space-between", alignItems: "center", backgroundColor: "#A9DAD6" }}
>
<Text style={{ fontWeight: "bold", fontSize:20 }}>
{" "}{title}
</Text>
{arguments[1]
? <Icon style={{ fontSize: 18 }} name="remove-circle" />
: <Icon style={{ fontSize: 18 }} name="add-circle" />}
</View>
);
}
renderHeader({title}){
返回(
{“}{title}
{参数[1]
?
: }
);
}
@Guru,上面指定的问题是否仍然存在?在函数类型中添加内部对象格式。它起作用了
renderHeader({title}) {
return (
<View
style={{ flexDirection: "row", padding: 10, justifyContent: "space-between", alignItems: "center", backgroundColor: "#A9DAD6" }}
>
<Text style={{ fontWeight: "bold", fontSize:20 }}>
{" "}{title}
</Text>
{arguments[1]
? <Icon style={{ fontSize: 18 }} name="remove-circle" />
: <Icon style={{ fontSize: 18 }} name="add-circle" />}
</View>
);
}