List 列表

定义/Definition

列表以一致的格式来显示一组相关的内容,为一致性的类型或者一组内容指定优先顺序来体现层次感以获取更好的可读性。列表也可以包含多行的文本,并且文本的字数可以在同一列表的不同瓦片间有所不同。

规则 / Rule

确保内容列对齐,文字左对齐,数字右对齐。

代码演示

基本

最简单的用法。

  1. import { List, Switch } from 'antd-mobile';
  2. import { createForm } from 'rc-form';
  3. let ListExample = React.createClass({
  4. render() {
  5. const { getFieldProps } = this.props.form;
  6. return (<form>
  7. <List>
  8. <List.Header>列表头部,List.Header</List.Header>
  9. <List.Body>
  10. <List.Item
  11. extra={null}
  12. >标题文字,没有配置onClick则点击无反馈</List.Item>
  13. <List.Item
  14. onClick={() => {}}
  15. extra={undefined}
  16. >标题文字</List.Item>
  17. <List.Item
  18. extra="内容内容"
  19. onClick={() => {}}
  20. >标题文字</List.Item>
  21. </List.Body>
  22. <List.Footer>列表尾部,List.Footer</List.Footer>
  23. </List>
  24. <List>
  25. <List.Header>下拉框</List.Header>
  26. <List.Body>
  27. <List.Item
  28. extra={<select style={{ direction: 'rtl' }}
  29. {...getFieldProps('select1', {
  30. initialValue: 1,
  31. })}
  32. >
  33. <option value="1">选项1</option>
  34. <option value="2">选项2</option>
  35. <option value="3">选项3</option>
  36. </select>}
  37. arrow="horizontal"
  38. >下拉框</List.Item>
  39. <List.Item
  40. extra={<select style={{ direction: 'rtl' }} defaultValue="2">
  41. <option value="1">选项1</option>
  42. <option value="2">选项2</option>
  43. <option value="3" disabled>选项3不可选</option>
  44. </select>}
  45. arrow="horizontal"
  46. >下拉框</List.Item>
  47. <List.Item
  48. arrow="horizontal"
  49. >
  50. <select defaultValue="3">
  51. <option value="1">选项1</option>
  52. <option value="2" disabled>选项2不可选</option>
  53. <option value="3">选项3</option>
  54. </select>
  55. </List.Item>
  56. </List.Body>
  57. </List>
  58. <List>
  59. <List.Header>滑动开关Switch</List.Header>
  60. <List.Body>
  61. <List.Item
  62. extra={<Switch
  63. {...getFieldProps('1', {
  64. initialValue: true,
  65. valuePropName: 'checked',
  66. })}
  67. />}
  68. >默认开</List.Item>
  69. <List.Item
  70. extra={<Switch
  71. {...getFieldProps('2', {
  72. initialValue: false,
  73. valuePropName: 'checked',
  74. })}
  75. />}
  76. >默认关</List.Item>
  77. <List.Item
  78. extra={<Switch
  79. {...getFieldProps('3', {
  80. initialValue: false,
  81. valuePropName: 'checked',
  82. })}
  83. disabled
  84. />}
  85. >默认关,不可修改</List.Item>
  86. <List.Item
  87. extra={<Switch
  88. {...getFieldProps('4', {
  89. initialValue: true,
  90. valuePropName: 'checked',
  91. })}
  92. disabled
  93. />}
  94. >默认开,不可修改</List.Item>
  95. </List.Body>
  96. </List>
  97. <List>
  98. <List.Header>带缩略图</List.Header>
  99. <List.Body>
  100. <List.Item
  101. thumb="https://zos.alipayobjects.com/rmsportal/zotStpFiYpNtZNl.png"
  102. arrow="horizontal"
  103. >thumb</List.Item>
  104. <List.Item
  105. thumb="https://zos.alipayobjects.com/rmsportal/zotStpFiYpNtZNl.png"
  106. >thumb</List.Item>
  107. <List.Item
  108. icon=""
  109. extra={<img src="https://zos.alipayobjects.com/rmsportal/zotStpFiYpNtZNl.png" width="28" height="28" />}
  110. arrow="horizontal"
  111. >extra&lt;img /&gt;标签</List.Item>
  112. </List.Body>
  113. </List>
  114. </form>);
  115. },
  116. });
  117. ListExample = createForm()(ListExample);
  118. ReactDOM.render(<ListExample />, mountNode);
  1. /** hack for antd responsive conflict */
  2. @media only screen and (max-width: 767px) and (min-width: 320px) {
  3. #list {
  4. display: block;
  5. }
  6. }

箭头

单行列表

  1. import { List } from 'antd-mobile';
  2. window.clickItem = (e) => {
  3. console.log(e);
  4. console.log(this);
  5. console.log(ReactDOM.findDOMNode(this));
  6. console.log($(ReactDOM.findDOMNode(this)).find('.am-list-extra'));
  7. $(ReactDOM.findDOMNode(this)).find('.am-list-extra').css('color', 'red');
  8. };
  9. window.openurl = (e) => {
  10. e.preventDefault();
  11. let target = e.target;
  12. if (!$(target).hasClass('am-list-item')) {
  13. target = $(target).parents('.am-list-item')[0];
  14. }
  15. window.location.href = target.href;
  16. };
  17. ReactDOM.render(
  18. <div>
  19. <List>
  20. <List.Header>箭头</List.Header>
  21. <List.Body>
  22. <List.Item extra="horizontal,箭头向右" arrow="horizontal" onClick={() => {}}>标题文字</List.Item>
  23. <List.Item extra="down,箭头向下" arrow="down" onClick={() => {}}>标题文字</List.Item>
  24. <List.Item extra="up,箭头向上" arrow="up" onClick={() => {}}>标题文字</List.Item>
  25. <List.Item
  26. extra={<div>内容内容<div className="am-list-brief">辅助文字内容</div></div>}
  27. arrow="horizontal"
  28. onClick={() => {}}
  29. ><div className="am-list-title">标题文字</div><div className="am-list-brief">辅助文字内容</div></List.Item>
  30. <List.Item
  31. extra={<div>内容内容<div className="am-list-brief">辅助文字内容</div></div>}
  32. arrow="down"
  33. onClick={() => {}}
  34. ><div className="am-list-title">标题文字</div><div className="am-list-brief">辅助文字内容</div></List.Item>
  35. <List.Item
  36. extra={<div>内容内容<div className="am-list-brief">辅助文字内容</div></div>}
  37. arrow="up"
  38. error
  39. onClick={() => {}}
  40. ><div className="am-list-title">标题文字</div><div className="am-list-brief">辅助文字内容</div></List.Item>
  41. <List.Item
  42. extra="empty,有箭头坑位"
  43. arrow="empty"
  44. onClick={() => {}}
  45. >内容内容</List.Item>
  46. <List.Item
  47. extra="校验报错"
  48. error
  49. onClick={() => {}}
  50. >内容内容</List.Item>
  51. </List.Body>
  52. </List>
  53. </div>
  54. , mountNode);

对齐

双行列表

  1. import { List, Button } from 'antd-mobile';
  2. ReactDOM.render(
  3. <div>
  4. <List >
  5. <List.Header>对齐</List.Header>
  6. <List.Body>
  7. <List.Item
  8. extra={<div>内容内容<div className="am-list-brief">辅助文字内容</div><div className="am-list-brief">辅助文字内容</div></div>}
  9. arrow="horizontal"
  10. onClick={() => {}}
  11. >垂直居中对齐</List.Item>
  12. <List.Item
  13. extra="内容内容"
  14. arrow="horizontal"
  15. onClick={() => {}}
  16. ><div>垂直居中对齐<div className="am-list-brief">辅助文字内容</div><div className="am-list-brief">辅助文字内容</div></div></List.Item>
  17. <List.Item
  18. extra={<div>内容内容<div className="am-list-brief">辅助文字内容</div><div className="am-list-brief">辅助文字内容</div></div>}
  19. arrow="horizontal"
  20. align="top"
  21. onClick={() => {}}
  22. >顶部对齐</List.Item>
  23. <List.Item
  24. extra="内容内容"
  25. arrow="horizontal"
  26. align="top"
  27. onClick={() => {}}
  28. ><div>顶部对齐<div className="am-list-brief">辅助文字内容</div></div></List.Item>
  29. <List.Item
  30. extra={<div>内容内容<div className="am-list-brief">辅助文字内容</div></div>}
  31. arrow="horizontal"
  32. align="bottom"
  33. onClick={() => {}}
  34. >底部对齐</List.Item>
  35. <List.Item
  36. extra="内容内容"
  37. arrow="horizontal"
  38. align="bottom"
  39. onClick={() => {}}
  40. ><div>底部对齐<div className="am-list-brief">辅助文字内容</div></div></List.Item>
  41. <List.Item
  42. onClick={() => {}}
  43. extra={<Button
  44. size="small"
  45. inline
  46. onClick={() => alert(111)}
  47. >按钮</Button>}
  48. ><div><div className="am-list-title">区域经理</div><div className="am-list-brief">可进行收款、退款、折扣管理、查看数据等操作</div></div></List.Item>
  49. </List.Body>
  50. </List>
  51. </div>
  52. , mountNode);

业务示例

一个业务上使用的示例。

  1. import { List } from 'antd-mobile';
  2. ReactDOM.render(
  3. <div>
  4. <List>
  5. <List.Body>
  6. <List.Item
  7. extra="鹿港小镇"
  8. arrow="horizontal"
  9. onClick={() => {}}
  10. >所属门店</List.Item>
  11. <List.Item
  12. extra="张三"
  13. arrow="empty"
  14. onClick={() => {}}
  15. >员工姓名</List.Item>
  16. <List.Item
  17. extra="收银员"
  18. arrow="empty"
  19. onClick={() => {}}
  20. >员工角色</List.Item>
  21. <List.Item
  22. extra="13838383756"
  23. arrow="empty"
  24. onClick={() => {}}
  25. >员工手机</List.Item>
  26. <List.Item
  27. extra="只可退自己的"
  28. arrow="empty"
  29. onClick={() => {}}
  30. >退款权限</List.Item>
  31. <List.Item
  32. extra="其他权限"
  33. arrow="horizontal"
  34. onClick={() => {}}
  35. >文本信息</List.Item>
  36. <List.Item
  37. extra={<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAQAAAD9CzEMAAAAm0lEQVR4Ae2Whw0DMQwD5Q24gfbfRTslaPlGCGb6vyAe2tdzty1uArAlyz2RMgJLoggsSTUBfUwCSkD49jKCFnhgYegCaZgSIAGlokCHBDk1BR6YspMteHIfRqWbhMc714Y/aMF/Bdgw5mJh5HgmU2u2qITatEAQCEvCe53cp+v3T9ct0E92HH01bcGlBIEVRfDWMGUBU0aQ04I7BEwkp1QhR1sAAAAASUVORK5CYII=" width="29" height="29" />}
  38. arrow="horizontal"
  39. onClick={() => {}}
  40. >员工二维码</List.Item>
  41. <List.Item
  42. extra={<div><div className="am-list-title">zhifubao@alipay.com#</div><div className="am-list-brief">001</div></div>}
  43. arrow="horizontal"
  44. onClick={() => {}}
  45. >垂直居中对齐</List.Item>
  46. <List.Item
  47. extra={<div><div className="am-list-title">zhifubao@alipay.com#</div><div className="am-list-brief">001</div></div>}
  48. arrow="horizontal"
  49. align="top"
  50. onClick={() => {}}
  51. >顶部对齐</List.Item>
  52. <List.Item
  53. extra={<div><div className="am-list-title">zhifubao@alipay.com#</div><div className="am-list-brief">001</div></div>}
  54. arrow="horizontal"
  55. align="bottom"
  56. onClick={() => {}}
  57. >底部对齐</List.Item>
  58. <List.Item
  59. extra={<div><div className="am-list-title">zhifubao@alipay.com#</div><div className="am-list-brief">001</div></div>}
  60. arrow="horizontal"
  61. align="top"
  62. onClick={() => {}}
  63. ><div className="am-list-title am-list-multiline">zhifubao@alipay.com#zh#</div></List.Item>
  64. </List.Body>
  65. </List>
  66. </div>
  67. , mountNode);

List列表 - 图1

API

List

成员说明类型默认值

List.Header

成员说明类型默认值

List.Body

成员说明类型默认值
成员说明类型默认值

List.Item

成员说明类型可选值默认值
thumb缩略图imgsrc
extra右边内容String/HTML
arrow箭头方向(右,上,下),如果是empty,则存在对应的dom,但是不显示Stringhorizontalupdownempty、无
alignFlex 子元素垂直对齐Stringtopmiddlebottommiddle
onClick点击事件的回调函数Function
error报错样式,右侧文字颜色变成橙色Booleantruefalsefalse