源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

javascript表格的渲染组件

  • 时间:2020-07-18 01:17 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:javascript表格的渲染组件
表格的渲染组件,demo请点击[url=http://lovewebgames.com/jsmodule/table.html]http://lovewebgames.com/jsmodule/table.html[/url],git源码请点击[url=https://github.com/tianxiangbing/table]https://github.com/tianxiangbing/table[/url] 如上图所示,功能基本包括常用表格中遇到的分页、搜索、删除、AJAX操作。由于是用的HANDLEBARS渲染的,所以样式可能很好的控制,要加新的功能也较容易。 调用例子 html
<div class="form">
  名称: <input type="text" name="gname"> <a href="#" id="search">search</a>
</div>
<div id="tab-list" ajaxurl="list.json">
  loading...
</div>
<div id="pager"></div>

模板
<script type="text/x-handlebars-template" id="tpl-list">
  <table class="tab-list">
    <thead>
      <tr>
          <th class="first-cell">序号</th>
          <th>商品条码</th>
          <th>商品名称</th>
          <th>状态</th>
          <th>操作</th>
      </tr>
    </thead>
    <tbody>
      {{#each data}}
      <tr>
          <td class="first-cell">{{@index}}</td>
          <td>{{goods_bn}}</td>
          <td>{{goods_name}}</td>
          <td>上架</td>
          <td><a class="js-ajax" js-ajax-param="id={{goods_id}}" href="action.json">下架</a> <a class="js-delete" href="action.json">删除</a></td>
      </tr>
      {{/each}}
    </tbody>
  </table>
</script>

js
<script>
  var table = new Table($('#tab-list'), $('#tpl-list'), $('#pager'), {}, $('#search'));
  table.init({type:'post'});
</script>

属性和方法 constuctor:function(table, temp, page, param, search, callback, filterCon) 构造函数,table是指存放表格的容器,可以是一个空的div,也可以是table里的一个tbody; temp是指表格的模板,这里是script节点的jquery对象 page 需要放置分页控件的容器 param 初始化带的参数 type json search 搜索按钮节点,你的祖先级中要有一个class为form的节点,会利用[query]([url=https://github.com/tianxiangbing/query]https://github.com/tianxiangbing/query[/url])格式化里面为参数,进行查询数据操作 callback 加载后的回调 filterCon 筛选过滤 init:function(settings) init是启动方法,目前的settings中仅包含{type:'get'} ,ajax请求的类型 以上所述就是本文的全部内容了,希望大家能够喜欢。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部