javascript表格的渲染組件_javascript技巧

來源:互聯網
上載者:User

表格的渲染組件,demo請點擊http://lovewebgames.com/jsmodule/table.html,git源碼請點擊https://github.com/tianxiangbing/table

如上圖所示,功能基本包括常用表格中遇到的分頁、搜尋、刪除、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](https://github.com/tianxiangbing/query)格式化裡面為參數,進行查詢資料操作
callback 載入後的回調
filterCon 篩選過濾

init:function(settings)
init是啟動方法,目前的settings中僅包含{type:'get'} ,ajax請求的類型

以上所述就是本文的全部內容了,希望大家能夠喜歡。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.