List 列表

单个连续模块垂直排列,显示当前的内容、状态和可进行的操作。eg:联系人列表。

规则

  • 一般由主要信息、主要操作、次要信息、次要操作组成。

  • 主要信息和主要操作放在列表的左边,次要信息和次要操作放在列表的右边。

代码演示

列表项类表单组件大集合(rc-form的基础用法请查看源码)

表单集合. (rc-form 文档,更多用法请详细阅读此文档)

  1. import { List, InputItem, Switch, Stepper, Slider, Radio, TextareaItem, WingBlank, WhiteSpace, Button } from 'antd-mobile';
  2. import { createForm } from 'rc-form';
  3. let BasicInput = React.createClass({
  4. getInitialState() {
  5. return {
  6. disabled: false,
  7. value: 1,
  8. };
  9. },
  10. handleChange(e) {
  11. if (e.target.checked) {
  12. this.setState({
  13. value: 1,
  14. });
  15. }
  16. },
  17. handleChange2(e) {
  18. if (e.target.checked) {
  19. this.setState({
  20. value: 2,
  21. });
  22. }
  23. },
  24. onSubmit() {
  25. this.props.form.validateFields({ force: true }, (error, values) => {
  26. if (!error) {
  27. const formValue = this.props.form.getFieldsValue();
  28. console.log(values);
  29. console.log(formValue);
  30. } else {
  31. alert('校验失败');
  32. }
  33. });
  34. },
  35. onReset() {
  36. this.props.form.resetFields();
  37. alert('重制完成');
  38. },
  39. validateAccount(rule, value, callback) {
  40. if (value && value.length > 4) {
  41. callback();
  42. } else {
  43. callback(new Error('帐号至少4个字符'));
  44. }
  45. },
  46. render() {
  47. const { getFieldProps, getFieldError } = this.props.form;
  48. return (<div>
  49. <List
  50. title="表单输入项"
  51. footer={getFieldError('account') && getFieldError('account').join(',')}
  52. >
  53. <InputItem
  54. {...getFieldProps('account', {
  55. initialValue: '小蚂蚁',
  56. rules: [
  57. { required: true, message: '请输入帐号' },
  58. { validator: this.validateAccount },
  59. ],
  60. })}
  61. clear
  62. error={!!getFieldError('account')}
  63. onErrorClick={() => {
  64. alert(getFieldError('account').join('、'));
  65. }}
  66. >帐号</InputItem>
  67. <InputItem
  68. {...getFieldProps('password')}
  69. clear
  70. placeholder="请输入密码"
  71. type="password"
  72. >密码</InputItem>
  73. <InputItem
  74. {...getFieldProps('input1', {
  75. initialValue: '1245',
  76. })}
  77. clear
  78. error
  79. placeholder="校验样式"
  80. type="password"
  81. >密码</InputItem>
  82. </List>
  83. <List
  84. title="表单展示项"
  85. >
  86. <List.Item
  87. thumb="https://zos.alipayobjects.com/rmsportal/dNuvNrtqUztHCwM.png"
  88. arrow="horizontal"
  89. >我的钱包</List.Item>
  90. <List.Item
  91. thumb="https://zos.alipayobjects.com/rmsportal/UmbJMbWOejVOpxe.png"
  92. arrow="horizontal"
  93. >我的花销占比</List.Item>
  94. </List>
  95. <List
  96. title="表单控件"
  97. >
  98. <List.Item
  99. extra={<Switch
  100. {...getFieldProps('1', {
  101. initialValue: true,
  102. valuePropName: 'checked',
  103. })}
  104. />}
  105. >使用 Ant Desgin Component</List.Item>
  106. <List.Item>
  107. <Slider range defaultValue={[20, 50]} />
  108. </List.Item>
  109. <List.Item
  110. extra={<Stepper showNumber size="small" max={10} min={1} defaultValue={20} onChange={() => {}} />}
  111. >预定人数</List.Item>
  112. </List>
  113. <List>
  114. <TextareaItem
  115. {...getFieldProps('note7', {
  116. initialValue: '如果你有什么建议意见,欢迎你来吐槽',
  117. })}
  118. labelNumber={4}
  119. name="yyy"
  120. rows={5}
  121. placeholder="计数功能"
  122. clear
  123. count={100}
  124. onBlur={() => { console.log('onBlur'); }}
  125. onFocus={(e) => { console.log('onFocus'); console.log(e); }}
  126. />
  127. </List>
  128. <List
  129. title="列表单选"
  130. >
  131. <Radio.RadioItem
  132. checked={this.state.value === 1}
  133. onChange={this.handleChange}
  134. disabled={this.state.disabled}
  135. >
  136. 选项一
  137. </Radio.RadioItem>
  138. <Radio.RadioItem
  139. checked={this.state.value === 2}
  140. onChange={this.handleChange2}
  141. disabled={this.state.disabled}
  142. >
  143. 选项二
  144. </Radio.RadioItem>
  145. <Radio.RadioItem
  146. checked
  147. onChange={this.handleChange}
  148. disabled
  149. >
  150. 选项三
  151. </Radio.RadioItem>
  152. <Radio.RadioItem
  153. checked={false}
  154. onChange={this.handleChange}
  155. disabled
  156. >
  157. 选项四
  158. </Radio.RadioItem>
  159. </List>
  160. <WhiteSpace />
  161. <WingBlank size="lg">
  162. <Button type="primary" onClick={this.onSubmit}>提交验证</Button>
  163. <WhiteSpace />
  164. <Button onClick={this.onReset}>重置</Button>
  165. </WingBlank>
  166. <WhiteSpace />
  167. <WhiteSpace />
  168. </div>);
  169. },
  170. });
  171. BasicInput = createForm()(BasicInput);
  172. ReactDOM.render(<BasicInput />, mountNode);

基本

基本用法. (rc-form 文档)

  1. import { List } from 'antd-mobile';
  2. import { createForm } from 'rc-form';
  3. let ListExample = React.createClass({
  4. render() {
  5. return (<form>
  6. <List
  7. title="我是华丽丽的列表头部"
  8. footer="我是列表尾部"
  9. >
  10. <List.Item>没有设置onClick则点击无反馈,文字超长则隐藏</List.Item>
  11. <List.Item wrap>文字超长折行文字超长折行文字超长折行文字超长折行文字超长折行文字超长折行</List.Item>
  12. <List.Item
  13. onClick={() => {}}
  14. extra={undefined}
  15. >标题文字</List.Item>
  16. <List.Item
  17. extra="内容内容"
  18. onClick={() => {}}
  19. arrow="horizontal"
  20. >标题文字</List.Item>
  21. </List>
  22. <List
  23. title="下拉框"
  24. >
  25. <List.Item
  26. extra={<select style={{ direction: 'rtl' }} defaultValue="2">
  27. <option value="1">选项1</option>
  28. <option value="2">选项2</option>
  29. <option value="3" disabled>选项3不可选</option>
  30. </select>}
  31. arrow="horizontal"
  32. >下拉框</List.Item>
  33. <List.Item
  34. arrow="horizontal"
  35. >
  36. <select defaultValue="3">
  37. <option value="1">选项1</option>
  38. <option value="2" disabled>选项2不可选</option>
  39. <option value="3">选项3</option>
  40. </select>
  41. </List.Item>
  42. </List>
  43. <List
  44. title="带缩略图"
  45. >
  46. <List.Item
  47. thumb="https://zos.alipayobjects.com/rmsportal/zotStpFiYpNtZNl.png"
  48. arrow="horizontal"
  49. onClick={() => {}}
  50. >thumb</List.Item>
  51. <List.Item
  52. thumb="https://zos.alipayobjects.com/rmsportal/zotStpFiYpNtZNl.png"
  53. >thumb</List.Item>
  54. <List.Item
  55. icon=""
  56. extra={<img src="https://zos.alipayobjects.com/rmsportal/zotStpFiYpNtZNl.png" width="28" height="28" />}
  57. arrow="horizontal"
  58. >extraimg标签</List.Item>
  59. </List>
  60. </form>);
  61. },
  62. });
  63. ListExample = createForm()(ListExample);
  64. 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. title="箭头方向"
  21. >
  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>内容内容<List.Item.Brief>辅助文字内容</List.Item.Brief></div>}
  27. arrow="horizontal"
  28. onClick={() => {}}
  29. multipleLine
  30. >标题文字<List.Item.Brief>辅助文字内容</List.Item.Brief></List.Item>
  31. <List.Item
  32. extra={<div>内容内容<List.Item.Brief>辅助文字内容</List.Item.Brief></div>}
  33. arrow="down"
  34. onClick={() => {}}
  35. multipleLine
  36. >标题文字<List.Item.Brief>辅助文字内容</List.Item.Brief></List.Item>
  37. <List.Item
  38. extra={<div>内容内容<List.Item.Brief>辅助文字内容</List.Item.Brief></div>}
  39. arrow="up"
  40. error
  41. onClick={() => {}}
  42. multipleLine
  43. >标题文字<List.Item.Brief>辅助文字内容</List.Item.Brief></List.Item>
  44. <List.Item
  45. extra="empty,有箭头坑位"
  46. arrow="empty"
  47. onClick={() => {}}
  48. multipleLine
  49. >内容内容</List.Item>
  50. <List.Item
  51. extra="校验报错"
  52. error
  53. onClick={() => {}}
  54. >内容内容</List.Item>
  55. </List>
  56. </div>
  57. , mountNode);

对齐方式

双行列表

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

业务示例

一个业务上使用的示例。

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

List列表 - 图1

API

List

成员说明类型默认值
titlelist titleReactNode
footerlist footerReactNode

List.Item

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

List.Item.Brief

辅助说明