- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的代码中,我得到了低于数组值的值,并根据 SectionList 中的键填充这些值。所有键值在 UI 中都正确,但在我的渲染项中我面临一些问题。请参阅下面的第二部分,我已经解释了更多信息。基本上在渲染函数中我也想传递键值
//下面是数组值
customerSearch:[
{
"key": "Customer",
"data": [
{
"name": "John",
"status": "Active",
"nationalId": "NBGVH6676",
"flag": "cus",
},
{ "name": "Abhi",
"status": "Active",
"nationalId": "NBGVH6890",
"flag": "cus"
}
]
},
{
"key": "Requests",
"data": [
{
"name": "Request 1",
"status": "Active",
"nationalId": "K0089"
},
{ "name": "Request 2",
"status": "Active",
"nationalId": "AS420"
}
]
},
{
"key": "Invoice",
"data": [
{
"name": "Invoice No 1",
"status": "Active",
"nationalId": "IN998"
},
{ "name": "Invoice No 2",
"status": "Active",
"nationalId": "ABh007"
}
]
},
]
//这里我在特定键内填充数据在我这里,我得到了键值内的数组。虽然我必须在“客户”键中添加一些条件,但我必须显示头像。但这里没有键值出现。请帮忙
renderItems = ({ item }) => (
<View>
{key==='Customer' ?
<View style={{ flex: 1, flexDirection: 'row', margin: 10,padding:5}}>
<Avatar avatarSize={50}
name={item.name}
isTouchable={false} />
<View style={{ flex: 1, flexDirection: 'column', justifyContent: 'center' }}>
<Text style={{ flex: 1, color: '#00678F', fontSize: hp('2.3%'), fontWeight: 'bold', marginLeft: 5 }}>
{item.name}
</Text>
<Text style={{ flex: 1, color: '#121212', fontSize: hp('2.3%'), marginTop: 5, marginLeft: 10 }}>
National Id : {item.id}
</Text>
{
item.status === 'Active' ?
<View style={{
flex: 1,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'flex-start',
width: 100,
paddingLeft:5
}}>
<View style={{
padding: 5,
backgroundColor: '#2CAC40',
borderRadius: 20,
height: 10,
width: 10,
marginTop: 4,
marginRight: 4,
}} />
<Text note
style={{ flex: 1, color: '#2CAC40', fontSize: hp('2.3%'), justifyContent: 'center' }}>
{item.status}
</Text>
</View> :
<View style={{
flex: 1,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'flex-start',
width: 100,
}}>
<View style={{
padding: 5,
backgroundColor: '#CC2828',
borderRadius: 20,
height: 10,
width: 10,
marginTop: 4,
marginRight: 4
}} />
<Text note style={{ flex: 1, color: '#CC2828', fontSize: hp('2.2%') }}>
{item.status}
</Text>
</View>
}
</View>
</View>:
<View style={{ flex: 1, flexDirection: 'row', margin: 5,padding:5}}>
<View style={{ flex: 1, flexDirection: 'column', justifyContent: 'center' }}>
<Text style={{ flex: 1, color: '#00678F', fontSize: hp('2.3%'), fontWeight: 'bold', marginLeft: 5 }}>
{item.name}
</Text>
<Text style={{ flex: 1, color: '#121212', fontSize: hp('2.3%'), marginTop: 5, marginLeft: 5,paddingBottom:10 }}>
National Id : {item.nationId}
</Text>
<View style={{ width: '100%', height: '.5%', backgroundColor: 'black' }}></View>
</View>
</View>}
</View>
)
//渲染函数中的以下代码
<View style={{ marginLeft: 5, marginRight: 5, marginTop: 5, backgroundColor: '#fff' }}>
<SafeAreaView style={{ flex: 1, marginTop: 20 }}>
<SectionList
sections={globalSearchData}
keyExtractor={(item, index) => item + index}
renderSectionHeader={({ section }) => (
<RegularText text={`${section.key}`} textColor={parentStyle[appliedTheme] ? parentStyle[appliedTheme][appliedMode].signatureHeadingColor : null} style={{ fontSize: hp('2.5%') ,paddingLeft:15}}/>
)}
renderItem={this.renderItems}
/>
</SafeAreaView>
</View>
Example UI display
Customer
Name
Status
National ID
Name Status
National ID
Request
Name Status
National ID
Name Status
National ID
谢谢
最佳答案
在您的 renderItems
方法中,您还需要解构 section
。然后您可以使用 section.key
访问 key 。
代码:
renderItems = ({ item, section }) => (
const key = section.key;
// other Code ...
);
关于javascript - 如何根据SectionList中的键填充ui上数组的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60845977/
所以我有一个包含数据的数组 var today = "2020-08-31" var array = [ { name: "Joshua", id: 1, date: "2020-08-3
我有下面的json结构 { "title": "Name(s)", "type": "Text", "data": [ { "source": "DB",
我是 react-native 的新手,尝试过使用 SectionList。到目前为止一切正常。但是,我似乎无法使用 facebook 文档中定义的 scrollToLocation 函数。有人试过使
您好,我有一个 sectionList,它传递了一组颜色 + 随机选择的背景 img,以呈现为每个行项目的背景。当我滑动访问该 View 时,颜色会闪烁几秒钟,因为随机选择仍在发生。每次我返回带有列表
我的 API 服务有以下数组结构 [ { id: 1001, orderNo: 'abc', customer: 'John', date: 15245262186
我有带部分的列表,但是这个 ListView 很慢。 我需要任何支架,但我不知道怎么做。 当我只有一种 View 时很简单,但在这里我遇到了问题。 我创建了 holder,但是当 ListView 显
我在使用 SectionList 组件时遇到问题,有时它不会呈现所有部分,而是只呈现第一部分。我已经进行了一些调试并且可能找到了修复方法,但我不知道为什么它可以解决问题。 我的页面总是会呈现第一部分,
我正在尝试显示一个包含多个列的部分列表。由于部分列表没有开箱即用的功能,我认为为每个部分项目呈现一个平面列表可能是个好主意。但我没有让它工作。 import React, { Component }
如果有这个简单的SectionList我的代码中的定义: const s = ( abc} renderSectionHeader={({ section }) => abc}
这个问题在这里已经有了答案: Basic FlatList code throws Warning - React Native (13 个回答) 4年前关闭。 我正在关注 SectionLists
我们可以添加像这个库一样的选项卡https://github.com/bogoslavskiy/react-native-tabs-section-list在部分列表中。我尝试了上面的库,它已经过时并
我对 React 和 React Native 还很陌生,但是在填充 SectionList 时遇到了问题,而且还找不到解决方案。 我有一个对象数组,每个对象都有它自己的数组。 SectionList
我正在使用 react-native 的 SectionList 并且无法隐藏数据集空白部分的部分标题。我只想显示部分标题和非空部分的行。 最佳答案 这就是我所做的: ( section
跟随 RN SectionList文档。如果我想像示例中那样构建同质部分列表: } renderSectionHeader={({section}) => } sections={[ //
我刚刚将我的 ListView 更改为 React Native 的新 SectionList,现在当我尝试使用 scrollTo 函数时应用程序崩溃,并指出它未定义。我尝试查找可能有帮助的新功能/替
我正在使用不同的节标题来呈现多个节。我在按我想要的方式显示它时遇到了一些麻烦。我希望我的标题位于顶部和下方,该部分的元素作为网格。 This is what I have right now 使用这段
使用 SectionList 时,虽然调用了 renderItem,但不会显示行。在列表上触发滚动时,行会立即出现。 我在 GitHub 上发现了一个问题讨论这个问题,但我没有找到任何解决方案来解决它
你知道如何在 sectionList 组件 React-native 中制作水平部分(特定)吗?我想让第二部分水平,我尝试使用 flex:1 和 flexDirection: 'row' 修改 ren
我有一个呈现多行的 SectionList。我正在尝试点击 renderItem 中的 View 。但我无法通过其 ID 访问该 View 。 I have used this to tap the
对于我正在处理的项目,我需要创建一个组件,用户可以在其中向处于状态的数组添加条目,还有一个 SectionList以显示这些条目。此外,我需要 SectionList 在输入后立即向下滚动到最新条目。
我是一名优秀的程序员,十分优秀!