-
Notifications
You must be signed in to change notification settings - Fork 19
/
Bootstrap-Table guide.html
1 lines (1 loc) · 62.4 KB
/
Bootstrap-Table guide.html
1
<!-- build time:Wed Mar 09 2022 10:17:52 GMT+0800 (GMT+08:00) --><!doctype html><html class="theme-next mist" lang="zh-Hans"><head><meta name="generator" content="Hexo 3.8.0"><meta name="google-site-verification" content="7Tau9WyVgxnsEY9oYedu9g0U6_8akOX3wiKbaYcrg9A"><meta name="baidu-site-verification" content="EVwLiaxdxX"><link href="/css/xps13.css" rel="stylesheet" type="text/css"><link href="/css/message.css" rel="stylesheet" type="text/css"><link href="//fonts.googleapis.com/css?family=Baloo+Bhaijaan|Inconsolata|Josefin+Sans|Montserrat" rel="stylesheet"><script type="text/javascript" src="/js/jquery-1.11.3.min.js"></script><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css"><link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css"><meta name="keywords" content="Bootstrap,"><link rel="alternate" href="/atom.xml" title="MrBird" type="application/atom+xml"><link rel="shortcut icon" type="image/x-icon" href="/bird.png?v=5.1.1"><meta name="description" content="Bootstrap Table是一款基于Bootstrap的jQuery表格插件,通过简单的设置,就可以拥有强大的单选、多选、排序、分页,以及编辑、导出、过滤、扩展等等的功能。作者地址:https://github.com/wenzhixin/bootstrap-table。这里简单介绍下使用方法以及对其进行二次封装,方便日常开发使用。"><meta name="keywords" content="Bootstrap"><meta property="og:type" content="article"><meta property="og:title" content="Bootstrap Table学习指南"><meta property="og:url" content="http://mrbird.cc/Bootstrap-Table guide.html"><meta property="og:site_name" content="MrBird"><meta property="og:description" content="Bootstrap Table是一款基于Bootstrap的jQuery表格插件,通过简单的设置,就可以拥有强大的单选、多选、排序、分页,以及编辑、导出、过滤、扩展等等的功能。作者地址:https://github.com/wenzhixin/bootstrap-table。这里简单介绍下使用方法以及对其进行二次封装,方便日常开发使用。"><meta property="og:locale" content="zh-Hans"><meta property="og:image" content="http://mrbird.cc/img/QQ截图20180314172620.png"><meta property="og:updated_time" content="2020-01-21T03:30:03.121Z"><meta name="twitter:card" content="summary"><meta name="twitter:title" content="Bootstrap Table学习指南"><meta name="twitter:description" content="Bootstrap Table是一款基于Bootstrap的jQuery表格插件,通过简单的设置,就可以拥有强大的单选、多选、排序、分页,以及编辑、导出、过滤、扩展等等的功能。作者地址:https://github.com/wenzhixin/bootstrap-table。这里简单介绍下使用方法以及对其进行二次封装,方便日常开发使用。"><meta name="twitter:image" content="http://mrbird.cc/img/QQ截图20180314172620.png"><script type="text/javascript" id="hexo.configurations">var NexT=window.NexT||{},CONFIG={root:"/",scheme:"Mist",sidebar:{position:"left",display:"always",offset:12,offset_float:0,b2t:!1,scrollpercent:!0},fancybox:!1,motion:!1}</script><title>Bootstrap Table学习指南 | MrBird</title></head><body ondragstart="return!1" class="animsition" lang="zh-Hans" style="overflow-x:hidden;padding-left:280px"><script type="text/javascript" src="/js/mo.min.js"></script><style>body{text-rendering:geometricPrecision!important;font-family:'Josefin Sans','PingFang SC'!important;-webkit-font-smoothing:antialiased!important;-webkit-text-size-adjust:100%!important;background-color:#f4f6f7}@media (min-width:768px) and (max-width:991px){body .header-innerr{width:700px!important}}.header-innerr{margin:0 auto;padding:100px 0 70px;width:880px}@media (min-width:1600px){.container .header-innerr{width:996px}}.header-innerr{position:relative}.header-innerr{padding:0}.header-innerr:after,.header-innerr:before{content:" ";display:table}.header-innerr:after{clear:both}@media (max-width:767px){.header-innerr{width:auto;padding:10px;margin-bottom:-20px}}</style><div class="container sidebar-position-left page-post-detail"><div class="headband"></div><header id="header" class="header"><div class="header-inner"><div class="site-brand-wrapper"><div class="site-meta"><link href="https://fonts.font.im/css?family=Merienda" rel="stylesheet"><div class="custom-logo-site-title"></div><h1 class="site-subtitle" itemprop="description"></h1></div><div class="site-nav-toggle"><button><span class="btn-bar"></span> <span class="btn-bar"></span> <span class="btn-bar"></span></button></div></div><nav class="site-nav"><div class="site-search"><div class="popup search-popup local-search-popup"><div class="local-search-header clearfix"><span class="search-icon"><i class="fa fa-search"></i> </span><span class="popup-btn-close"><i class="fa fa-times-circle"></i></span><div class="local-search-input-wrapper"><input autocomplete="off" placeholder="Search" spellcheck="false" type="text" id="local-search-input"></div></div><div id="local-search-result"></div></div></div></nav></div><div class="header-innerr"></div></header><main id="main" class="main"><div class="main-inner"><div class="content-wrap"><div id="content" class="content"><div id="posts" class="posts-expand"><article class="post post-type-normal" itemscope itemtype="http://schema.org/Article"><link itemprop="mainEntityOfPage" href="http://mrbird.cc/Bootstrap-Table guide.html"><span hidden itemprop="author" itemscope itemtype="http://schema.org/Person"><meta itemprop="name" content="MrBird"><meta itemprop="description" content=""><meta itemprop="image" content="/images/blogImage.jpg"></span><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="MrBird"></span><header class="post-header"><h2 class="post-title" itemprop="name headline">Bootstrap Table学习指南</h2><div class="post-meta"><span class="post-time"><span class="post-meta-item-icon"><i class="fa fa-calendar-o"></i> </span><span class="post-meta-item-text"></span> <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-01-06T09:43:13+08:00">2018-01-06 </time></span><span></span> <span class="post-meta-divider">|</span> <span class="page-pv"><i class="fa fa-laptop"></i> Visit count <span class="busuanzi-value" id="busuanzi_value_page_pv"></span></span></div></header><div class="post-body" itemprop="articleBody"><p>Bootstrap Table是一款基于Bootstrap的jQuery表格插件,通过简单的设置,就可以拥有强大的单选、多选、排序、分页,以及编辑、导出、过滤、扩展等等的功能。作者地址:<a href="https://github.com/wenzhixin/bootstrap-table" target="_blank" rel="noopener">https://github.com/wenzhixin/bootstrap-table</a>。这里简单介绍下使用方法以及对其进行二次封装,方便日常开发使用。<a id="more"></a></p><h2 id="准备工作"><a href="#准备工作" class="headerlink" title="准备工作"></a>准备工作</h2><p>因为基于Bootstrap,所以先引入Bootstrap依赖:</p><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">link</span> <span class="attr">rel</span>=<span class="string">"stylesheet"</span> <span class="attr">href</span>=<span class="string">"https://cdn.bootcss.com/bootstrap/4.0.0/css/bootstrap.min.css"</span>></span></span><br><span class="line"><span class="tag"><<span class="name">script</span> <span class="attr">src</span>=<span class="string">"http://code.jquery.com/jquery-2.0.0.min.js"</span>></span><span class="undefined"></span><span class="tag"></<span class="name">script</span>></span></span><br><span class="line"><span class="tag"><<span class="name">script</span> <span class="attr">src</span>=<span class="string">"https://cdn.bootcss.com/popper.js/1.12.9/umd/popper.min.js"</span>></span><span class="undefined"></span><span class="tag"></<span class="name">script</span>></span></span><br><span class="line"><span class="tag"><<span class="name">script</span> <span class="attr">src</span>=<span class="string">"https://cdn.bootcss.com/bootstrap/4.0.0/js/bootstrap.min.js"</span>></span><span class="undefined"></span><span class="tag"></<span class="name">script</span>></span></span><br></pre></td></tr></table></figure><p></p><p>然后引入Bootstrap Table依赖:</p><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"><!-- Latest compiled and minified CSS --></span></span><br><span class="line"><span class="tag"><<span class="name">link</span> <span class="attr">rel</span>=<span class="string">"stylesheet"</span> <span class="attr">href</span>=<span class="string">"//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.9.0/bootstrap-table.min.css"</span>></span></span><br><span class="line"><span class="comment"><!-- Latest compiled and minified JavaScript --></span></span><br><span class="line"><span class="tag"><<span class="name">script</span> <span class="attr">src</span>=<span class="string">"//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.9.0/bootstrap-table.min.js"</span>></span><span class="undefined"></span><span class="tag"></<span class="name">script</span>></span></span><br><span class="line"><span class="comment"><!-- Latest compiled and minified Locales --></span></span><br><span class="line"><span class="tag"><<span class="name">script</span> <span class="attr">src</span>=<span class="string">"//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.9.0/locale/bootstrap-table-zh-CN.min.js"</span>></span><span class="undefined"></span><span class="tag"></<span class="name">script</span>></span></span><br></pre></td></tr></table></figure><p></p><h2 id="数据准备"><a href="#数据准备" class="headerlink" title="数据准备"></a>数据准备</h2><p>本例中使用到的数据表SQL如下:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- ----------------------------</span></span><br><span class="line"><span class="comment">-- Table structure for T_ROLE</span></span><br><span class="line"><span class="comment">-- ----------------------------</span></span><br><span class="line"><span class="keyword">DROP</span> <span class="keyword">TABLE</span> <span class="string">"MRBIRD"</span>.<span class="string">"T_ROLE"</span>;</span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> <span class="string">"MRBIRD"</span>.<span class="string">"T_ROLE"</span> (</span><br><span class="line"><span class="string">"ROLE_ID"</span> <span class="built_in">NUMBER</span> <span class="keyword">NOT</span> <span class="literal">NULL</span> ,</span><br><span class="line"><span class="string">"ROLE_NAME"</span> VARCHAR2(<span class="number">100</span> <span class="keyword">BYTE</span>) <span class="keyword">NOT</span> <span class="literal">NULL</span> ,</span><br><span class="line"><span class="string">"REMARK"</span> VARCHAR2(<span class="number">100</span> <span class="keyword">BYTE</span>) <span class="literal">NULL</span> ,</span><br><span class="line"><span class="string">"CREATE_TIME"</span> <span class="built_in">DATE</span> <span class="keyword">NOT</span> <span class="literal">NULL</span> ,</span><br><span class="line"><span class="string">"MODIFY_TIME"</span> <span class="built_in">DATE</span> <span class="literal">NULL</span> </span><br><span class="line">);</span><br><span class="line"></span><br><span class="line"><span class="comment">-- ----------------------------</span></span><br><span class="line"><span class="comment">-- Records of T_ROLE</span></span><br><span class="line"><span class="comment">-- ----------------------------</span></span><br><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> <span class="string">"MRBIRD"</span>.<span class="string">"T_ROLE"</span> <span class="keyword">VALUES</span> (<span class="string">'23'</span>, <span class="string">'用户管理员'</span>, <span class="string">'负责用户的增删改操作'</span>, <span class="keyword">TO_DATE</span>(<span class="string">'2018-01-09 15:32:41'</span>, <span class="string">'YYYY-MM-DD HH24:MI:SS'</span>), <span class="literal">null</span>);</span><br><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> <span class="string">"MRBIRD"</span>.<span class="string">"T_ROLE"</span> <span class="keyword">VALUES</span> (<span class="string">'1'</span>, <span class="string">'管理员'</span>, <span class="string">'管理员'</span>, <span class="keyword">TO_DATE</span>(<span class="string">'2017-12-27 16:23:11'</span>, <span class="string">'YYYY-MM-DD HH24:MI:SS'</span>), <span class="keyword">TO_DATE</span>(<span class="string">'2018-02-24 16:01:45'</span>, <span class="string">'YYYY-MM-DD HH24:MI:SS'</span>));</span><br><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> <span class="string">"MRBIRD"</span>.<span class="string">"T_ROLE"</span> <span class="keyword">VALUES</span> (<span class="string">'2'</span>, <span class="string">'测试账号'</span>, <span class="string">'测试账号'</span>, <span class="keyword">TO_DATE</span>(<span class="string">'2017-12-27 16:25:09'</span>, <span class="string">'YYYY-MM-DD HH24:MI:SS'</span>), <span class="keyword">TO_DATE</span>(<span class="string">'2018-01-23 09:11:11'</span>, <span class="string">'YYYY-MM-DD HH24:MI:SS'</span>));</span><br><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> <span class="string">"MRBIRD"</span>.<span class="string">"T_ROLE"</span> <span class="keyword">VALUES</span> (<span class="string">'3'</span>, <span class="string">'注册账户'</span>, <span class="string">'注册账户,只可查看,不可操作'</span>, <span class="keyword">TO_DATE</span>(<span class="string">'2017-12-29 16:00:15'</span>, <span class="string">'YYYY-MM-DD HH24:MI:SS'</span>), <span class="keyword">TO_DATE</span>(<span class="string">'2018-02-24 17:33:45'</span>, <span class="string">'YYYY-MM-DD HH24:MI:SS'</span>));</span><br><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> <span class="string">"MRBIRD"</span>.<span class="string">"T_ROLE"</span> <span class="keyword">VALUES</span> (<span class="string">'24'</span>, <span class="string">'系统监控员'</span>, <span class="string">'可查看系统监控信息,但不可操作'</span>, <span class="keyword">TO_DATE</span>(<span class="string">'2018-01-09 15:52:01'</span>, <span class="string">'YYYY-MM-DD HH24:MI:SS'</span>), <span class="keyword">TO_DATE</span>(<span class="string">'2018-03-07 19:05:33'</span>, <span class="string">'YYYY-MM-DD HH24:MI:SS'</span>));</span><br><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> <span class="string">"MRBIRD"</span>.<span class="string">"T_ROLE"</span> <span class="keyword">VALUES</span> (<span class="string">'25'</span>, <span class="string">'用户查看'</span>, <span class="string">'查看用户,无相应操作权限'</span>, <span class="keyword">TO_DATE</span>(<span class="string">'2018-01-09 15:56:30'</span>, <span class="string">'YYYY-MM-DD HH24:MI:SS'</span>), <span class="literal">null</span>);</span><br><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> <span class="string">"MRBIRD"</span>.<span class="string">"T_ROLE"</span> <span class="keyword">VALUES</span> (<span class="string">'63'</span>, <span class="string">'影院工作者'</span>, <span class="string">'可查看影视信息'</span>, <span class="keyword">TO_DATE</span>(<span class="string">'2018-02-06 08:48:28'</span>, <span class="string">'YYYY-MM-DD HH24:MI:SS'</span>), <span class="keyword">TO_DATE</span>(<span class="string">'2018-03-07 19:05:26'</span>, <span class="string">'YYYY-MM-DD HH24:MI:SS'</span>));</span><br><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> <span class="string">"MRBIRD"</span>.<span class="string">"T_ROLE"</span> <span class="keyword">VALUES</span> (<span class="string">'64'</span>, <span class="string">'天气预报员'</span>, <span class="string">'可查看天气预报信息'</span>, <span class="keyword">TO_DATE</span>(<span class="string">'2018-02-27 08:47:04'</span>, <span class="string">'YYYY-MM-DD HH24:MI:SS'</span>), <span class="literal">null</span>);</span><br><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> <span class="string">"MRBIRD"</span>.<span class="string">"T_ROLE"</span> <span class="keyword">VALUES</span> (<span class="string">'65'</span>, <span class="string">'文章审核'</span>, <span class="string">'文章类'</span>, <span class="keyword">TO_DATE</span>(<span class="string">'2018-02-27 08:48:01'</span>, <span class="string">'YYYY-MM-DD HH24:MI:SS'</span>), <span class="keyword">TO_DATE</span>(<span class="string">'2018-03-13 11:20:34'</span>, <span class="string">'YYYY-MM-DD HH24:MI:SS'</span>));</span><br></pre></td></tr></table></figure><p></p><p>后端框架为Spring Boot + MyBatis(通用mapper和pagehelper插件),获取数据的具体细节这里不再描述,可参考文末的源码。</p><h2 id="使用"><a href="#使用" class="headerlink" title="使用"></a>使用</h2><p>编写一个简单的页面:</p><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">form</span> <span class="attr">class</span>=<span class="string">"form"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"row"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"col"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"input-group"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">span</span> <span class="attr">class</span>=<span class="string">"input-group-addon"</span>></span>角色:<span class="tag"></<span class="name">span</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"form-group"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">input</span> <span class="attr">type</span>=<span class="string">"text"</span> <span class="attr">name</span>=<span class="string">"roleName"</span> <span class="attr">class</span>=<span class="string">"form-control"</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">div</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">div</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">div</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"col"</span>></span><span class="tag"></<span class="name">div</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"col"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">button</span> <span class="attr">type</span>=<span class="string">"button"</span> <span class="attr">class</span>=<span class="string">"btn btn-success"</span> <span class="attr">onclick</span>=<span class="string">"refresh()"</span>></span>重置<span class="tag"></<span class="name">button</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">button</span> <span class="attr">type</span>=<span class="string">"button"</span> <span class="attr">class</span>=<span class="string">"btn btn-primary"</span> <span class="attr">onclick</span>=<span class="string">"search()"</span>></span>搜索<span class="tag"></<span class="name">button</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">div</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">div</span>></span></span><br><span class="line"><span class="tag"></<span class="name">form</span>></span></span><br><span class="line"><span class="tag"><<span class="name">table</span> <span class="attr">id</span>=<span class="string">"roleTable"</span> <span class="attr">data-mobile-responsive</span>=<span class="string">"true"</span> <span class="attr">class</span>=<span class="string">"mb-bootstrap-table text-nowrap"</span>></span><span class="tag"></<span class="name">table</span>></span></span><br></pre></td></tr></table></figure><p></p><p>Bootstrap Table插件的使用:</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line">$(<span class="string">'#roleTable'</span>).bootstrapTable({</span><br><span class="line"> method: <span class="string">'get'</span>, <span class="comment">// 服务器数据的请求方式 get or post</span></span><br><span class="line"> url: ctx + <span class="string">"bootstrap-table/list"</span>, <span class="comment">// 服务器数据的加载地址</span></span><br><span class="line"> striped: <span class="literal">true</span>, <span class="comment">//是否显示行间隔色</span></span><br><span class="line"> cache: <span class="literal">false</span>, <span class="comment">//是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)</span></span><br><span class="line"> pagination: <span class="literal">true</span>, <span class="comment">//是否显示分页(*)</span></span><br><span class="line"> sortable: <span class="literal">false</span>, <span class="comment">//是否启用排序</span></span><br><span class="line"> sidePagination: <span class="string">"server"</span>, <span class="comment">//分页方式:client客户端分页,server服务端分页(*)</span></span><br><span class="line"> pageNumber: <span class="number">1</span>, <span class="comment">//初始化加载第一页,默认第一页</span></span><br><span class="line"> pageSize: <span class="number">5</span>, <span class="comment">//每页的记录行数(*)</span></span><br><span class="line"> pageList: [<span class="number">5</span>, <span class="number">25</span>, <span class="number">50</span>, <span class="number">100</span>], <span class="comment">//可供选择的每页的行数(*)</span></span><br><span class="line"> strictSearch: <span class="literal">true</span>,</span><br><span class="line"> minimumCountColumns: <span class="number">2</span>, <span class="comment">//最少允许的列数</span></span><br><span class="line"> clickToSelect: <span class="literal">true</span>, <span class="comment">//是否启用点击选中行</span></span><br><span class="line"> uniqueId: <span class="string">"ID"</span>, <span class="comment">//每一行的唯一标识,一般为主键列</span></span><br><span class="line"> cardView: <span class="literal">false</span>,</span><br><span class="line"> detailView: <span class="literal">false</span>, <span class="comment">//是否显示详细视图</span></span><br><span class="line"> smartDisplay: <span class="literal">false</span>,</span><br><span class="line"> queryParams: <span class="function"><span class="keyword">function</span>(<span class="params">params</span>) </span>{</span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> pageSize: params.limit,</span><br><span class="line"> pageNum: params.offset / params.limit + <span class="number">1</span>,</span><br><span class="line"> roleName: $(<span class="string">".form"</span>).find(<span class="string">"input[name='roleName']"</span>).val().trim(),</span><br><span class="line"> };</span><br><span class="line"> },</span><br><span class="line"> columns: [{</span><br><span class="line"> checkbox: <span class="literal">true</span></span><br><span class="line"> },{</span><br><span class="line"> field: <span class="string">'roleId'</span>,</span><br><span class="line"> title: <span class="string">'角色ID'</span></span><br><span class="line"> },{</span><br><span class="line"> field: <span class="string">'roleName'</span>,</span><br><span class="line"> title: <span class="string">'角色'</span></span><br><span class="line"> }, {</span><br><span class="line"> field: <span class="string">'remark'</span>,</span><br><span class="line"> title: <span class="string">'描述'</span></span><br><span class="line"> }, {</span><br><span class="line"> field: <span class="string">'createTime'</span>,</span><br><span class="line"> title: <span class="string">'创建时间'</span></span><br><span class="line"> }, {</span><br><span class="line"> field: <span class="string">'modifyTime'</span>,</span><br><span class="line"> title: <span class="string">'修改时间'</span></span><br><span class="line"> }]</span><br><span class="line">});</span><br><span class="line"><span class="comment">// 搜索方法</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">search</span>(<span class="params"></span>) </span>{</span><br><span class="line"> $(<span class="string">'#roleTable'</span>).bootstrapTable(<span class="string">'refresh'</span>);</span><br><span class="line">}</span><br><span class="line"><span class="comment">// 重置方法</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">refresh</span>(<span class="params"></span>) </span>{</span><br><span class="line"> $(<span class="string">".form"</span>)[<span class="number">0</span>].reset();</span><br><span class="line"> search();</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p></p><p>后端返回的JSON数据如下所示:</p><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><span class="line">{</span><br><span class="line"> <span class="attr">"total"</span>: <span class="number">9</span>,</span><br><span class="line"> <span class="attr">"rows"</span>: [{</span><br><span class="line"> <span class="attr">"roleId"</span>: <span class="number">1</span>,</span><br><span class="line"> <span class="attr">"roleName"</span>: <span class="string">"管理员"</span>,</span><br><span class="line"> <span class="attr">"remark"</span>: <span class="string">"管理员"</span>,</span><br><span class="line"> <span class="attr">"createTime"</span>: <span class="number">1514362991000</span>,</span><br><span class="line"> <span class="attr">"modifyTime"</span>: <span class="number">1519459305000</span></span><br><span class="line"> }, {</span><br><span class="line"> <span class="attr">"roleId"</span>: <span class="number">2</span>,</span><br><span class="line"> <span class="attr">"roleName"</span>: <span class="string">"测试账号"</span>,</span><br><span class="line"> <span class="attr">"remark"</span>: <span class="string">"测试账号"</span>,</span><br><span class="line"> <span class="attr">"createTime"</span>: <span class="number">1514363109000</span>,</span><br><span class="line"> <span class="attr">"modifyTime"</span>: <span class="number">1516669871000</span></span><br><span class="line"> }, {</span><br><span class="line"> <span class="attr">"roleId"</span>: <span class="number">3</span>,</span><br><span class="line"> <span class="attr">"roleName"</span>: <span class="string">"注册账户"</span>,</span><br><span class="line"> <span class="attr">"remark"</span>: <span class="string">"注册账户,只可查看,不可操作"</span>,</span><br><span class="line"> <span class="attr">"createTime"</span>: <span class="number">1514534415000</span>,</span><br><span class="line"> <span class="attr">"modifyTime"</span>: <span class="number">1519464825000</span></span><br><span class="line"> }, {</span><br><span class="line"> <span class="attr">"roleId"</span>: <span class="number">23</span>,</span><br><span class="line"> <span class="attr">"roleName"</span>: <span class="string">"用户管理员"</span>,</span><br><span class="line"> <span class="attr">"remark"</span>: <span class="string">"负责用户的增删改操作"</span>,</span><br><span class="line"> <span class="attr">"createTime"</span>: <span class="number">1515483161000</span>,</span><br><span class="line"> <span class="attr">"modifyTime"</span>: <span class="literal">null</span></span><br><span class="line"> }, {</span><br><span class="line"> <span class="attr">"roleId"</span>: <span class="number">24</span>,</span><br><span class="line"> <span class="attr">"roleName"</span>: <span class="string">"系统监控员"</span>,</span><br><span class="line"> <span class="attr">"remark"</span>: <span class="string">"可查看系统监控信息,但不可操作"</span>,</span><br><span class="line"> <span class="attr">"createTime"</span>: <span class="number">1515484321000</span>,</span><br><span class="line"> <span class="attr">"modifyTime"</span>: <span class="number">1520420733000</span></span><br><span class="line"> }, {</span><br><span class="line"> <span class="attr">"roleId"</span>: <span class="number">25</span>,</span><br><span class="line"> <span class="attr">"roleName"</span>: <span class="string">"用户查看"</span>,</span><br><span class="line"> <span class="attr">"remark"</span>: <span class="string">"查看用户,无相应操作权限"</span>,</span><br><span class="line"> <span class="attr">"createTime"</span>: <span class="number">1515484590000</span>,</span><br><span class="line"> <span class="attr">"modifyTime"</span>: <span class="literal">null</span></span><br><span class="line"> }, {</span><br><span class="line"> <span class="attr">"roleId"</span>: <span class="number">63</span>,</span><br><span class="line"> <span class="attr">"roleName"</span>: <span class="string">"影院工作者"</span>,</span><br><span class="line"> <span class="attr">"remark"</span>: <span class="string">"可查看影视信息"</span>,</span><br><span class="line"> <span class="attr">"createTime"</span>: <span class="number">1517878108000</span>,</span><br><span class="line"> <span class="attr">"modifyTime"</span>: <span class="number">1520420726000</span></span><br><span class="line"> }, {</span><br><span class="line"> <span class="attr">"roleId"</span>: <span class="number">64</span>,</span><br><span class="line"> <span class="attr">"roleName"</span>: <span class="string">"天气预报员"</span>,</span><br><span class="line"> <span class="attr">"remark"</span>: <span class="string">"可查看天气预报信息"</span>,</span><br><span class="line"> <span class="attr">"createTime"</span>: <span class="number">1519692424000</span>,</span><br><span class="line"> <span class="attr">"modifyTime"</span>: <span class="literal">null</span></span><br><span class="line"> }, {</span><br><span class="line"> <span class="attr">"roleId"</span>: <span class="number">65</span>,</span><br><span class="line"> <span class="attr">"roleName"</span>: <span class="string">"文章审核"</span>,</span><br><span class="line"> <span class="attr">"remark"</span>: <span class="string">"文章类"</span>,</span><br><span class="line"> <span class="attr">"createTime"</span>: <span class="number">1519692481000</span>,</span><br><span class="line"> <span class="attr">"modifyTime"</span>: <span class="number">1520911234000</span></span><br><span class="line"> }]</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p></p><p>页面显示效果如下: <img src="img/QQ截图20180314172620.png" alt="QQ截图20180314172620.png"></p><h2 id="二次封装"><a href="#二次封装" class="headerlink" title="二次封装"></a>二次封装</h2><p>实际使用中除了几个常用的参数比如url,queryParams,columns等等之外,剩下的参数一般默认就好,所以接下来对其进行二次封装,使得开发中更为方便。</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> $Mrbird = (<span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>{</span><br><span class="line"> <span class="keyword">var</span> bootstrapTable_default = {</span><br><span class="line"> method: <span class="string">'get'</span>,</span><br><span class="line"> striped: <span class="literal">true</span>,</span><br><span class="line"> cache: <span class="literal">false</span>,</span><br><span class="line"> pagination: <span class="literal">true</span>,</span><br><span class="line"> sortable: <span class="literal">false</span>,</span><br><span class="line"> sidePagination: <span class="string">"server"</span>,</span><br><span class="line"> pageNumber: <span class="number">1</span>,</span><br><span class="line"> pageSize: <span class="number">5</span>,</span><br><span class="line"> pageList: [<span class="number">5</span>, <span class="number">10</span>, <span class="number">25</span>, <span class="number">50</span>, <span class="number">100</span>],</span><br><span class="line"> strictSearch: <span class="literal">true</span>,</span><br><span class="line"> showColumns: <span class="literal">false</span>,</span><br><span class="line"> minimumCountColumns: <span class="number">2</span>,</span><br><span class="line"> clickToSelect: <span class="literal">true</span>,</span><br><span class="line"> uniqueId: <span class="string">"ID"</span>,</span><br><span class="line"> cardView: <span class="literal">false</span>,</span><br><span class="line"> detailView: <span class="literal">false</span>,</span><br><span class="line"> smartDisplay: <span class="literal">false</span>,</span><br><span class="line"> queryParams: <span class="function"><span class="keyword">function</span>(<span class="params">params</span>) </span>{</span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> pageSize: params.limit,</span><br><span class="line"> pageNum: params.offset / params.limit + <span class="number">1</span>,</span><br><span class="line"> };</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="function"><span class="keyword">function</span> <span class="title">_initTable</span>(<span class="params">id, settings</span>) </span>{</span><br><span class="line"> <span class="keyword">var</span> params = $.extend({}, bootstrapTable_default, settings);</span><br><span class="line"> <span class="keyword">if</span> (<span class="keyword">typeof</span> params.url == <span class="string">'undefined'</span>) {</span><br><span class="line"> <span class="keyword">throw</span> <span class="string">'初始化表格失败,请配置url参数!'</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (<span class="keyword">typeof</span> params.columns == <span class="string">'undefined'</span>) {</span><br><span class="line"> <span class="keyword">throw</span> <span class="string">'初始化表格失败,请配置columns参数!'</span>;</span><br><span class="line"> }</span><br><span class="line"> $(<span class="string">'#'</span> + id).bootstrapTable(params);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> initTable: <span class="function"><span class="keyword">function</span>(<span class="params">id, settings</span>) </span>{</span><br><span class="line"> _initTable(id, settings);</span><br><span class="line"> },</span><br><span class="line"> refreshTable: <span class="function"><span class="keyword">function</span>(<span class="params">id</span>) </span>{</span><br><span class="line"> $(<span class="string">'#'</span> + id).bootstrapTable(<span class="string">'refresh'</span>);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">})($);</span><br></pre></td></tr></table></figure><p></p><p>这样,在使用Bootstap Table插件的时候只需要像下面这样书写即可:</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line">$(<span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>{</span><br><span class="line"> <span class="keyword">var</span> settings = {</span><br><span class="line"> url: ctx + <span class="string">"bootstrap-table/list"</span>,</span><br><span class="line"> queryParams: <span class="function"><span class="keyword">function</span>(<span class="params">params</span>) </span>{</span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> pageSize: params.limit,</span><br><span class="line"> pageNum: params.offset / params.limit + <span class="number">1</span>,</span><br><span class="line"> roleName: $(<span class="string">".form"</span>).find(<span class="string">"input[name='roleName']"</span>).val().trim(),</span><br><span class="line"> };</span><br><span class="line"> },</span><br><span class="line"> columns: [{</span><br><span class="line"> checkbox: <span class="literal">true</span></span><br><span class="line"> },</span><br><span class="line"> {</span><br><span class="line"> field: <span class="string">'roleId'</span>,</span><br><span class="line"> title: <span class="string">'角色ID'</span></span><br><span class="line"> }, {</span><br><span class="line"> field: <span class="string">'roleName'</span>,</span><br><span class="line"> title: <span class="string">'角色'</span></span><br><span class="line"> }, {</span><br><span class="line"> field: <span class="string">'remark'</span>,</span><br><span class="line"> title: <span class="string">'描述'</span></span><br><span class="line"> }, {</span><br><span class="line"> field: <span class="string">'createTime'</span>,</span><br><span class="line"> title: <span class="string">'创建时间'</span></span><br><span class="line"> }, {</span><br><span class="line"> field: <span class="string">'modifyTime'</span>,</span><br><span class="line"> title: <span class="string">'修改时间'</span></span><br><span class="line"> }</span><br><span class="line"> ]</span><br><span class="line"> }</span><br><span class="line"> $Mrbird.initTable(<span class="string">'roleTable'</span>, settings);</span><br><span class="line">});</span><br></pre></td></tr></table></figure><p></p><h2 id="附录"><a href="#附录" class="headerlink" title="附录"></a>附录</h2><p>Bootstap Table除了上面介绍的内容外,其还包含了许多别的特性,可参考官方文档:<a href="http://bootstrap-table.wenzhixin.net.cn/zh-cn/documentation/" target="_blank" rel="noopener">http://bootstrap-table.wenzhixin.net.cn/zh-cn/documentation/</a>。</p><p>源码链接:<a href="https://drive.google.com/open?id=1qEVgDDBfbdaVJ1FSckzQr6RAUyGF7k6J" target="_blank" rel="noopener">https://drive.google.com/open?id=1qEVgDDBfbdaVJ1FSckzQr6RAUyGF7k6J</a></p><script>$(".post-body a").not(".thispage").addClass("ignore-href").attr("target","_blank")</script></div><div></div><div><div style="padding:10px 0;margin:20px auto;width:90%;text-align:center;color:#878787" id="reward-div"><div>请作者喝瓶肥宅水🥤</div><button id="rewardButton" style="margin-top:10px" disable="enable" onclick='var e=document.getElementById("QR");"none"===e.style.display?e.style.display="block":e.style.display="none"'><span style="height:46px;width:46px;line-height:46px;border-radius:50%;color:#fe5f55;font-weight:600;background:#ffd5be;border:none;box-shadow:0 4px 8px 0 rgba(255,213,190,.4)">¥</span></button><div id="QR" style="display:none"><div id="wechat" style="display:inline-block"><img id="wechat_qr" src="/img/wechat_pay.png" alt="MrBird WeChat Pay"></div><div id="alipay" style="display:inline-block"><img id="alipay_qr" src="/img/ali_pay.png" alt="MrBird Alipay"></div></div></div><style>#QR img{width:auto;margin:.8em 1em 0 1em}</style></div><div><ul class="post-copyright"><li class="post-copyright-author"><strong>本文作者:</strong> MrBird</li><li class="post-copyright-link"><strong>本文链接:</strong> <a href="http://mrbird.cc/Bootstrap-Table guide.html" title="Bootstrap Table学习指南">http://mrbird.cc/Bootstrap-Table guide.html</a></li><li class="post-copyright-license"><strong>版权声明: </strong>本博客所有文章除特别声明外,均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明出处!</li></ul></div><footer class="post-footer"><div class="post-tags" style="margin-bottom:1.3rem"><a href="/tags/Bootstrap/" rel="tag"># Bootstrap</a></div><div class="post-nav"><div class="post-nav-next post-nav-item"><a href="/Linux Spring-Boot-jar.html" rel="next" title="Linux下部署Spring Boot jar"><i class="fa fa-chevron-left"></i> Linux下部署Spring Boot jar</a></div><span class="post-nav-divider"></span><div class="post-nav-prev post-nav-item"><a href="/jQuery-TreeGrid.html" rel="prev" title="树形表格插件jQuery TreeGrid">树形表格插件jQuery TreeGrid <i class="fa fa-chevron-right"></i></a></div></div></footer></article><hr><div id="container"></div><div class="post-spread"><div id="comment-div"></div><style>.valine .vlist{margin-bottom:3rem}.valine .vwrap .vcontrol .col.col-60{text-align:left}.valine .vlist .vcard .vhead,.valine .vlist .vcard section .vfooter{text-align:left}.valine .vlist .vcard section{padding-bottom:.5rem!important}.vname{color:#6db33f!important}div#comment-div{margin-bottom:-8rem}.valine .vlist .vcard .vcontent .code,.valine .vlist .vcard .vcontent code,.valine .vlist .vcard .vcontent pre{background:#fbfbfb}.valine .vlist .vcard .vcontent a{color:#6db33f}.valine .vlist .vcard .vimg{border-radius:3px}.valine .vinfo{text-align:left}.valine .vbtn{border-radius:2px;padding:.3rem 1.25rem}.valine .vbtn:active,.valine .vbtn:hover{color:#6db33f;border-color:#6db33f;background-color:#fff}.valine .vwrap .vheader .vinput:focus{border-bottom-color:#6db33f}.valine .vlist .vcard .vcontent.expand:before{background:-webkit-gradient(linear,left top,left bottom,from(hsla(0,0%,100%,0)),to(hsla(0,0%,100%,.2)));background:linear-gradient(180deg,hsla(0,0%,100%,0),hsla(0,0%,100%,.2))}.valine .vlist .vcard .vcontent.expand:after{content:"点击展开";font-size:.4rem;text-align:right;left:-1rem;background:hsla(0,0%,100%,.2)}.valine .vlist .vcard section .vfooter .vat{color:#b3b3b3}.valine .vlist .vcard section .vfooter .vat:hover{color:#6db33f}.vcontent img{margin:0}.valine .info{display:none}</style><script type="text/javascript" src="/js/av.min.js"></script><script type="text/javascript" src="/js/Valine.min.js"></script><script type="text/javascript" src="/js/activate-power-mode.js"></script><script>POWERMODE.colorful=!0,POWERMODE.shake=!1,document.body.addEventListener("input",POWERMODE),new Valine({el:"#comment-div",notify:!1,verify:!0,appId:"SMcDFP1bN1jgb9Lo8JmtICHm-gzGzoHsz",appKey:"dH4nrUrt3V5XiJiI6Qyejnbi",placeholder:"",path:window.location.pathname,avatar:"monsterid",guest_info:["nick","mail","link"]});var chicken='<a href="#"><img src="https://image.uisdc.com/wp-content/uploads/2018/06/uisdc-chat-chicken.gif" class="checken"></a>';$("#comment-div").prepend(chicken)</script></div></div><script>var $bqinline=$("img[alt='bq-inline']");$bqinline.css({width:"2.3rem",height:"2.3rem",display:"inline","vertical-align":"text-bottom"})</script></div><div class="comments" id="comments"></div></div><aside id="sidebar" class="sidebar" onselectstart="return!1"><div class="sidebar-inner"><ul class="sidebar-nav motion-element"><li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">Contents</li><li class="sidebar-nav-overview" data-target="site-overview">Site Preview</li></ul><section class="site-overview sidebar-panel"><div class="sidebar-sticky sticky"><div itemscope itemtype="https://mrbird.cc"><div class="author__header"><div class="author__avatar"><img src="/images/blogImage.jpg" class="author__avatar" alt="MrBird" itemprop="image"></div><div class="author__content"><div class="author__name" itemprop="name">MrBird</div><p class="author__bio" itemprop="description">A simple blog, code repository, just keep blogging</p></div><div class="author__count"><a href="/archives" class="ignore-href"><span class="count">14</span> <span>Archives</span> </a><a href="/tags" class="ignore-href"><span class="count">2</span> <span>Labels</span></a></div></div><div class="author__urls-wrapper"><ul class="author__urls social-icons"><li><a href="/" itemprop="url" class="ignore-href">🏠 Home</a></li><li><a href="/archives" itemprop="url" class="ignore-href">📦 Archives</a></li><li><a href="/tags" itemprop="url" class="ignore-href">🔖 Labels</a></li><li><a href="/friends" itemprop="url" class="ignore-href">👬 Friends</a></li><li><a href="javascript:;" class="popup-trigger animsition-link">🔍 Search</a></li></ul></div></div></div></section><section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active"><div class="post-toc"><div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#准备工作"><span class="nav-number">1.</span> <span class="nav-text">准备工作</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#数据准备"><span class="nav-number">2.</span> <span class="nav-text">数据准备</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#使用"><span class="nav-number">3.</span> <span class="nav-text">使用</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#二次封装"><span class="nav-number">4.</span> <span class="nav-text">二次封装</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#附录"><span class="nav-number">5.</span> <span class="nav-text">附录</span></a></li></ol></div></div></section></div><div id="asider-footer"><div id="links"><li><a href="https://love.mrbird.cc" target="_blank" itemprop="url" class="ignore-href"><i class="fa fa-fw fa-diamond" aria-hidden="true"></i></a></li><li><a href="https://cloud.mrbird.cn" target="_blank" itemprop="url" class="ignore-href"><i class="fa fa-fw fa-skyatlas" aria-hidden="true"></i></a></li><li><a href="https://gitee.com/mrbirdd" target="_blank" itemprop="sameAs" class="ignore-href"><i class="fa fa-fw fa-codepen" aria-hidden="true"></i></a></li><li><a href="https://github.com/wuyouzhuguli" target="_blank" itemprop="sameAs" class="ignore-href"><i class="fa fa-fw fa-github-alt" aria-hidden="true"></i></a></li></div><div id="author"></div><script type="text/javascript">var $smsheoschzd100dn="@ 2016 - "+(new Date).getFullYear()+" MrBird";document.getElementById("author").innerHTML=$smsheoschzd100dn</script><div><script type="text/javascript" src="/js/busuanzi.js"></script> UV <span class="busuanzi-value" id="busuanzi_value_site_uv" style="cursor:pointer" title="统计开始时间:2019年7月5日"></span> PV <span class="busuanzi-value" id="busuanzi_value_site_pv" style="cursor:pointer" title="统计开始时间:2019年7月5日"></span></div></div><script>function c__(){var o=sidebar_nav_toc.attr("class");o.indexOf("active")!=-1?footer.hide(300):footer.show(300)}var sidebar_nav_toc=$(".sidebar-nav-toc"),footer=$("#asider-footer");c__(),$(".sidebar-nav").on("click",function(){c__()})</script></aside></div></main><div class="back-to-top"><span id="scrollpercent"><span>0</span></span></div></div><script type="text/javascript">"[object Function]"!==Object.prototype.toString.call(window.Promise)&&(window.Promise=null)</script><script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script><script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script><script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script><script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script><script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script><script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script><script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script><script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script><script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script><script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script><script type="text/javascript">function proceedsearch(){$("body").append('<div class="search-popup-overlay local-search-pop-overlay"></div>').css("overflow","hidden"),$(".search-popup-overlay").click(onPopupClose),$(".popup").toggle();var t=$("#local-search-input");t.attr("autocapitalize","none"),t.attr("autocorrect","off"),t.focus()}var isfetched=!1,isXml=!0,search_path="search.xml";0===search_path.length?search_path="search.xml":search_path.endsWith("json")&&(isXml=!1);var path="/"+search_path,onPopupClose=function(t){$(".popup").hide(),$("#local-search-input").val(""),$(".search-result-list").remove(),$("#no-result").remove(),$(".local-search-pop-overlay").remove(),$("body").css("overflow","")},searchFunc=function(t,e,o){"use strict";$("body").append('<div class="search-popup-overlay local-search-pop-overlay"><div id="search-loading-icon"><i class="fa fa-spinner fa-pulse fa-2x fa-fw"></i></div></div>').css("overflow","hidden"),$("#search-loading-icon").css("margin","20% auto 0 auto").css("text-align","center"),$.ajax({url:t,dataType:isXml?"xml":"json",async:!0,success:function(t){isfetched=!0,$(".popup").detach().appendTo(".header-inner");var n=isXml?$("entry",t).map(function(){return{title:$("title",this).text(),content:$("content",this).text(),url:$("url",this).text()}}).get():t,r=document.getElementById(e),s=document.getElementById(o),a=function(){var t=r.value.trim().toLowerCase(),e=t.split(/[\s\-]+/);e.length>1&&e.push(t);var o=[];if(t.length>0&&n.forEach(function(n){function r(e,o,n,r){for(var s=r[r.length-1],a=s.position,i=s.word,l=[],h=0;a+i.length<=n&&0!=r.length;){i===t&&h++,l.push({position:a,length:i.length});var p=a+i.length;for(r.pop();0!=r.length&&(s=r[r.length-1],a=s.position,i=s.word,p>a);)r.pop()}return c+=h,{hits:l,start:o,end:n,searchTextCount:h}}function s(t,e){var o="",n=e.start;return e.hits.forEach(function(e){o+=t.substring(n,e.position);var r=e.position+e.length;o+='<b class="search-keyword">'+t.substring(e.position,r)+"</b>",n=r}),o+=t.substring(n,e.end)}var a=!1,i=0,c=0,l=n.title.trim(),h=l.toLowerCase(),p=n.content.trim().replace(/<[^>]+>/g,""),u=p.toLowerCase(),f=decodeURIComponent(n.url),d=[],g=[];if(""!=l&&(e.forEach(function(t){function e(t,e,o){var n=t.length;if(0===n)return[];var r=0,s=[],a=[];for(o||(e=e.toLowerCase(),t=t.toLowerCase());(s=e.indexOf(t,r))>-1;)a.push({position:s,word:t}),r=s+n;return a}d=d.concat(e(t,h,!1)),g=g.concat(e(t,u,!1))}),(d.length>0||g.length>0)&&(a=!0,i=d.length+g.length)),a){[d,g].forEach(function(t){t.sort(function(t,e){return e.position!==t.position?e.position-t.position:t.word.length-e.word.length})});var v=[];0!=d.length&&v.push(r(l,0,l.length,d));for(var C=[];0!=g.length;){var $=g[g.length-1],m=$.position,x=$.word,w=m-20,y=m+80;w<0&&(w=0),y<m+x.length&&(y=m+x.length),y>p.length&&(y=p.length),C.push(r(p,w,y,g))}C.sort(function(t,e){return t.searchTextCount!==e.searchTextCount?e.searchTextCount-t.searchTextCount:t.hits.length!==e.hits.length?e.hits.length-t.hits.length:t.start-e.start});var T=parseInt("1");T>=0&&(C=C.slice(0,T));var b="";b+=0!=v.length?"<li><a href='"+f+"' class='search-result-title'>"+s(l,v[0])+"</a>":"<li><a href='"+f+"' class='search-result-title'>"+l+"</a>",C.forEach(function(t){b+="<a href='"+f+'\'><p class="search-result">'+s(p,t)+"...</p></a>"}),b+="</li>",o.push({item:b,searchTextCount:c,hitCount:i,id:o.length})}}),1===e.length&&""===e[0])s.innerHTML='<div id="no-result"><i class="fa fa-search fa-5x" /></div>';else if(0===o.length)s.innerHTML='<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>';else{o.sort(function(t,e){return t.searchTextCount!==e.searchTextCount?e.searchTextCount-t.searchTextCount:t.hitCount!==e.hitCount?e.hitCount-t.hitCount:e.id-t.id});var a='<ul class="search-result-list">';o.forEach(function(t){a+=t.item}),a+="</ul>",s.innerHTML=a}};r.addEventListener("input",a),$(".local-search-pop-overlay").remove(),$("body").css("overflow",""),proceedsearch()}})};$(".popup-trigger").click(function(t){t.stopPropagation(),isfetched===!1?searchFunc(path,"local-search-input","local-search-result"):proceedsearch()}),$(".popup-btn-close").click(onPopupClose),$(".popup").click(function(t){t.stopPropagation()}),$(document).on("keyup",function(t){var e=27===t.which&&$(".search-popup").is(":visible");e&&onPopupClose()})</script></body><script>$(function(){$("a").not(".nav-link,.cloud-tie-join-count,.ignore-href,.jstree-anchor").addClass("animsition-link")});var burst1=new mojs.Burst({left:0,top:0,radius:{5:40},children:{shape:"circle",fill:["red","cyan","orange"],fillOpacity:.8,radiusX:3.5,radiusY:3.5}});document.addEventListener("click",function(a){null==a.target.href&&"footer"!=a.target.className&&"copyright"!=a.target.className&&"author__urls social-icons"!=a.target.className&&"author__avatar"!=a.target.className&&"sidebar sidebar-active"!=a.target.className&&burst1.tune({x:a.pageX,y:a.pageY}).generate().replay()})</script><script type="text/javascript" src="/js/message.js"></script></html><!-- rebuild by neat -->