Ken428965 2022-10-20 21:59 采纳率: 53.6%
浏览 18
已结题

react,使用antd mobile里的IndexBar序列组件,如何单独改变左边标题某一项的文字内容和样式?

已写的代码:

import React from 'react';
import { IndexBar, List } from 'antd-mobile';
import NavHeader from '../../components/NavHeader';
import './style.css';
const charCodeOfA = 'A'.charCodeAt(0);
  const groups = Array(26)
    .fill('')
    .map((_, i) => ({
    title: String.fromCharCode(charCodeOfA + i),
    items: [1,2,3,4,5],
}));
export default class CityList extends React.Component {
 
render() {
        return (
        <div className='citylist'>
        {/* 顶部导航栏 */}
        <NavHeader>城市选择</NavHeader>
{/* IndexBar序列 */}
  <div className='indexbar' style={{ height: window.innerHeight - 45 }}>
  <IndexBar>
        {groups.map(group => {
            const { title, items } = group;
            return (<IndexBar.Panel index={title} title={`标题${title}`} key={`标题${title}`}>
              <List>
                {items.map((item, index) => (<List.Item key={index}>{item}</List.Item>))}
              </List>
            </IndexBar.Panel>);
        })}
      </IndexBar>
      </div>
  </div>
        )
    }
}
 

目前效果如下:

img


请问如何才能单独将左边的“标题B”文字内容改为“热门城市”,并将其文字颜色设置成红色?

  • 写回答

1条回答 默认 最新

  • 崽崽的谷雨 2022-10-21 09:46
    关注

    看看 api 啊 brief 可以 自定义内容 甚至 样式都可以自定义 。不想要样式 就把 style去掉 。我看你截图 还有自己的样式。你把背景颜色换了

    img

    const briefFn=(title)=>{ // 右侧索引条中的显示内容
         if(title&&title=="当前城市"){
            return  <div style={{width:"16px",height:"16px",background:"red",borderRadius:"50%",textAlign:"center"}}>#</div>;
         }else{
            return title;
         }
       }
    
    

    img

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 10月21日
  • 已采纳回答 10月21日
  • 创建了问题 10月20日

悬赏问题

  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本