List 列表
定义/Definition
列表以一致的格式来显示一组相关的内容,为一致性的类型或者一组内容指定优先顺序来体现层次感以获取更好的可读性。列表也可以包含多行的文本,并且文本的字数可以在同一列表的不同瓦片间有所不同。
规则 / Rule
确保内容列对齐,文字左对齐,数字右对齐。
代码演示
基本
最简单的用法。
import { List, Switch } from 'antd-mobile';
import { createForm } from 'rc-form';
let ListExample = React.createClass({
render() {
const { getFieldProps } = this.props.form;
return (<form>
<List>
<List.Header>列表头部,List.Header</List.Header>
<List.Body>
<List.Item
extra={null}
>标题文字,没有配置onClick则点击无反馈</List.Item>
<List.Item
onClick={() => {}}
extra={undefined}
>标题文字</List.Item>
<List.Item
extra="内容内容"
onClick={() => {}}
>标题文字</List.Item>
</List.Body>
<List.Footer>列表尾部,List.Footer</List.Footer>
</List>
<List>
<List.Header>下拉框</List.Header>
<List.Body>
<List.Item
extra={<select style={{ direction: 'rtl' }}
{...getFieldProps('select1', {
initialValue: 1,
})}
>
<option value="1">选项1</option>
<option value="2">选项2</option>
<option value="3">选项3</option>
</select>}
arrow="horizontal"
>下拉框</List.Item>
<List.Item
extra={<select style={{ direction: 'rtl' }} defaultValue="2">
<option value="1">选项1</option>
<option value="2">选项2</option>
<option value="3" disabled>选项3不可选</option>
</select>}
arrow="horizontal"
>下拉框</List.Item>
<List.Item
arrow="horizontal"
>
<select defaultValue="3">
<option value="1">选项1</option>
<option value="2" disabled>选项2不可选</option>
<option value="3">选项3</option>
</select>
</List.Item>
</List.Body>
</List>
<List>
<List.Header>滑动开关Switch</List.Header>
<List.Body>
<List.Item
extra={<Switch
{...getFieldProps('1', {
initialValue: true,
valuePropName: 'checked',
})}
/>}
>默认开</List.Item>
<List.Item
extra={<Switch
{...getFieldProps('2', {
initialValue: false,
valuePropName: 'checked',
})}
/>}
>默认关</List.Item>
<List.Item
extra={<Switch
{...getFieldProps('3', {
initialValue: false,
valuePropName: 'checked',
})}
disabled
/>}
>默认关,不可修改</List.Item>
<List.Item
extra={<Switch
{...getFieldProps('4', {
initialValue: true,
valuePropName: 'checked',
})}
disabled
/>}
>默认开,不可修改</List.Item>
</List.Body>
</List>
<List>
<List.Header>带缩略图</List.Header>
<List.Body>
<List.Item
thumb="https://zos.alipayobjects.com/rmsportal/zotStpFiYpNtZNl.png"
arrow="horizontal"
>thumb</List.Item>
<List.Item
thumb="https://zos.alipayobjects.com/rmsportal/zotStpFiYpNtZNl.png"
>thumb</List.Item>
<List.Item
icon=""
extra={<img src="https://zos.alipayobjects.com/rmsportal/zotStpFiYpNtZNl.png" width="28" height="28" />}
arrow="horizontal"
>extra为<img />标签</List.Item>
</List.Body>
</List>
</form>);
},
});
ListExample = createForm()(ListExample);
ReactDOM.render(<ListExample />, mountNode);
/** hack for antd responsive conflict */
@media only screen and (max-width: 767px) and (min-width: 320px) {
#list {
display: block;
}
}
箭头
单行列表
import { List } from 'antd-mobile';
window.clickItem = (e) => {
console.log(e);
console.log(this);
console.log(ReactDOM.findDOMNode(this));
console.log($(ReactDOM.findDOMNode(this)).find('.am-list-extra'));
$(ReactDOM.findDOMNode(this)).find('.am-list-extra').css('color', 'red');
};
window.openurl = (e) => {
e.preventDefault();
let target = e.target;
if (!$(target).hasClass('am-list-item')) {
target = $(target).parents('.am-list-item')[0];
}
window.location.href = target.href;
};
ReactDOM.render(
<div>
<List>
<List.Header>箭头</List.Header>
<List.Body>
<List.Item extra="horizontal,箭头向右" arrow="horizontal" onClick={() => {}}>标题文字</List.Item>
<List.Item extra="down,箭头向下" arrow="down" onClick={() => {}}>标题文字</List.Item>
<List.Item extra="up,箭头向上" arrow="up" onClick={() => {}}>标题文字</List.Item>
<List.Item
extra={<div>内容内容<div className="am-list-brief">辅助文字内容</div></div>}
arrow="horizontal"
onClick={() => {}}
><div className="am-list-title">标题文字</div><div className="am-list-brief">辅助文字内容</div></List.Item>
<List.Item
extra={<div>内容内容<div className="am-list-brief">辅助文字内容</div></div>}
arrow="down"
onClick={() => {}}
><div className="am-list-title">标题文字</div><div className="am-list-brief">辅助文字内容</div></List.Item>
<List.Item
extra={<div>内容内容<div className="am-list-brief">辅助文字内容</div></div>}
arrow="up"
error
onClick={() => {}}
><div className="am-list-title">标题文字</div><div className="am-list-brief">辅助文字内容</div></List.Item>
<List.Item
extra="empty,有箭头坑位"
arrow="empty"
onClick={() => {}}
>内容内容</List.Item>
<List.Item
extra="校验报错"
error
onClick={() => {}}
>内容内容</List.Item>
</List.Body>
</List>
</div>
, mountNode);
对齐
双行列表
import { List, Button } from 'antd-mobile';
ReactDOM.render(
<div>
<List >
<List.Header>对齐</List.Header>
<List.Body>
<List.Item
extra={<div>内容内容<div className="am-list-brief">辅助文字内容</div><div className="am-list-brief">辅助文字内容</div></div>}
arrow="horizontal"
onClick={() => {}}
>垂直居中对齐</List.Item>
<List.Item
extra="内容内容"
arrow="horizontal"
onClick={() => {}}
><div>垂直居中对齐<div className="am-list-brief">辅助文字内容</div><div className="am-list-brief">辅助文字内容</div></div></List.Item>
<List.Item
extra={<div>内容内容<div className="am-list-brief">辅助文字内容</div><div className="am-list-brief">辅助文字内容</div></div>}
arrow="horizontal"
align="top"
onClick={() => {}}
>顶部对齐</List.Item>
<List.Item
extra="内容内容"
arrow="horizontal"
align="top"
onClick={() => {}}
><div>顶部对齐<div className="am-list-brief">辅助文字内容</div></div></List.Item>
<List.Item
extra={<div>内容内容<div className="am-list-brief">辅助文字内容</div></div>}
arrow="horizontal"
align="bottom"
onClick={() => {}}
>底部对齐</List.Item>
<List.Item
extra="内容内容"
arrow="horizontal"
align="bottom"
onClick={() => {}}
><div>底部对齐<div className="am-list-brief">辅助文字内容</div></div></List.Item>
<List.Item
onClick={() => {}}
extra={<Button
size="small"
inline
onClick={() => alert(111)}
>按钮</Button>}
><div><div className="am-list-title">区域经理</div><div className="am-list-brief">可进行收款、退款、折扣管理、查看数据等操作</div></div></List.Item>
</List.Body>
</List>
</div>
, mountNode);
业务示例
一个业务上使用的示例。
import { List } from 'antd-mobile';
ReactDOM.render(
<div>
<List>
<List.Body>
<List.Item
extra="鹿港小镇"
arrow="horizontal"
onClick={() => {}}
>所属门店</List.Item>
<List.Item
extra="张三"
arrow="empty"
onClick={() => {}}
>员工姓名</List.Item>
<List.Item
extra="收银员"
arrow="empty"
onClick={() => {}}
>员工角色</List.Item>
<List.Item
extra="13838383756"
arrow="empty"
onClick={() => {}}
>员工手机</List.Item>
<List.Item
extra="只可退自己的"
arrow="empty"
onClick={() => {}}
>退款权限</List.Item>
<List.Item
extra="其他权限"
arrow="horizontal"
onClick={() => {}}
>文本信息</List.Item>
<List.Item
extra={<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAQAAAD9CzEMAAAAm0lEQVR4Ae2Whw0DMQwD5Q24gfbfRTslaPlGCGb6vyAe2tdzty1uArAlyz2RMgJLoggsSTUBfUwCSkD49jKCFnhgYegCaZgSIAGlokCHBDk1BR6YspMteHIfRqWbhMc714Y/aMF/Bdgw5mJh5HgmU2u2qITatEAQCEvCe53cp+v3T9ct0E92HH01bcGlBIEVRfDWMGUBU0aQ04I7BEwkp1QhR1sAAAAASUVORK5CYII=" width="29" height="29" />}
arrow="horizontal"
onClick={() => {}}
>员工二维码</List.Item>
<List.Item
extra={<div><div className="am-list-title">zhifubao@alipay.com#</div><div className="am-list-brief">001</div></div>}
arrow="horizontal"
onClick={() => {}}
>垂直居中对齐</List.Item>
<List.Item
extra={<div><div className="am-list-title">zhifubao@alipay.com#</div><div className="am-list-brief">001</div></div>}
arrow="horizontal"
align="top"
onClick={() => {}}
>顶部对齐</List.Item>
<List.Item
extra={<div><div className="am-list-title">zhifubao@alipay.com#</div><div className="am-list-brief">001</div></div>}
arrow="horizontal"
align="bottom"
onClick={() => {}}
>底部对齐</List.Item>
<List.Item
extra={<div><div className="am-list-title">zhifubao@alipay.com#</div><div className="am-list-brief">001</div></div>}
arrow="horizontal"
align="top"
onClick={() => {}}
><div className="am-list-title am-list-multiline">zhifubao@alipay.com#zh#</div></List.Item>
</List.Body>
</List>
</div>
, mountNode);
API
List
List.Body
List.Item
成员 | 说明 | 类型 | 可选值 | 默认值 |
---|
thumb | 缩略图 | imgsrc | | 无 |
extra | 右边内容 | String/HTML | | 无 |
arrow | 箭头方向(右,上,下),如果是empty ,则存在对应的dom,但是不显示 | String | horizontal 、up 、down 、empty 、无 | 无 |
align | Flex 子元素垂直对齐 | String | top middle bottom | middle |
onClick | 点击事件的回调函数 | Function | | 无 |
error | 报错样式,右侧文字颜色变成橙色 | Boolean | true 、false | false |