使用 NativeBase 响应本机 - 是否可以在 Accordion 内容中显示和自定义包含多个数据集的数组?
React Native using NativeBase - Is it possible to show and customize an array with multiple data sets inside the Accordion content?
使用 NativeBase,我试图让 Accordion 内容显示多行 JSX 以及我稍后将获得的一些 JSON 数据。
在我看到的所有示例中,内容都设置为一个简单的字符串,但我想将它用于更多用途。
如果这是使用 NativeBase 的限制,我可以想出另一种方法来做到这一点,但它似乎应该很容易做到。
将用于填充 Accordion 的示例数据:
{ title: "First Element", content: "Lorem ipsum dolor sit amet" },
{ title: "Second Element", content: "Lorem ipsum dolor sit amet" },
{
title: "Third Element",
content: {
description: "Lorem ipsum dolor sit amet",
moreInfoItems: [
{ Item1: 1, Item2: 10, Item3: 225, Item4: 90 },
{ Item1: 2, Item2: 20, Item3: 325, Item4: 100 }
]
}
}
];
是的,可以,您可以使用renderContent
方法来呈现特殊内容格式数据。
...
<Accordion
dataArray={dataArray}
animation={true}
expanded={true}
renderHeader={this._renderHeader}
renderContent={this._renderContent}
/>
...
_renderContent(item){
// typeof can tell function,string array, object ..
if( typeof(item.content) == "string")
{
return (<Text>{item.content}</Text>)
}
// if it is a json or array
return (<Text
style={{
backgroundColor: "#e3f1f1",
padding: 10,
fontStyle: "italic",
}}
>
{item.content.description}
</Text>)
}
你想展示什么内容,你可以根据自己的情况来定义
使用 NativeBase,我试图让 Accordion 内容显示多行 JSX 以及我稍后将获得的一些 JSON 数据。
在我看到的所有示例中,内容都设置为一个简单的字符串,但我想将它用于更多用途。 如果这是使用 NativeBase 的限制,我可以想出另一种方法来做到这一点,但它似乎应该很容易做到。
将用于填充 Accordion 的示例数据:
{ title: "First Element", content: "Lorem ipsum dolor sit amet" },
{ title: "Second Element", content: "Lorem ipsum dolor sit amet" },
{
title: "Third Element",
content: {
description: "Lorem ipsum dolor sit amet",
moreInfoItems: [
{ Item1: 1, Item2: 10, Item3: 225, Item4: 90 },
{ Item1: 2, Item2: 20, Item3: 325, Item4: 100 }
]
}
}
];
是的,可以,您可以使用renderContent
方法来呈现特殊内容格式数据。
...
<Accordion
dataArray={dataArray}
animation={true}
expanded={true}
renderHeader={this._renderHeader}
renderContent={this._renderContent}
/>
...
_renderContent(item){
// typeof can tell function,string array, object ..
if( typeof(item.content) == "string")
{
return (<Text>{item.content}</Text>)
}
// if it is a json or array
return (<Text
style={{
backgroundColor: "#e3f1f1",
padding: 10,
fontStyle: "italic",
}}
>
{item.content.description}
</Text>)
}
你想展示什么内容,你可以根据自己的情况来定义