template and pagination

Posted norazhang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了template and pagination相关的知识,希望对你有一定的参考价值。

模板引擎和分页结构插件的使用方法

1. 引入插件

  <script src=" js/art-template/template-web.js"></script>

  <script src="js/twbs-pagination/jquery.twbsPagination.js"></script>

2. 创建模板

/*web.js 既支持原生语法,也支持简洁语法*/

  <script type="text.template id="tpl">

    遍历对象

    {{each aa as value index}}

      <li>{{value.name}}</li>

    {{/each}}

  </script>

 3.获取数据

   <script>

    /*发送ajax请求,得到数据*/

    $.ajax({

      type: get,

      url: get.php

      data:{id: id}

      success: function(res){

        if(res.code== 1){

          var data = res.data;

            /*res 是获得数据对象, data是对象力的数组

            1. template("tpl", res)  } ;    {{each data value}}  res是对象, 可以直接遍历里面的数组

            2. template("tpl",{aa: res.data}});  {{each aa value}} 给数组命名, 数组变成对象,可以直接遍历aa

            3. template("tpl", res.data) ;   {{each $data as value}}  res.data是数组, 不能直接遍历, $data是固定写法*/

 

          var html = template("tpl", {aa: res.data});

          document.querySelector("ul").innerHTML = html;

 

          4.分页结构插件的使用. 调用 twbsPagination() 方法

            方法里面传三个参数:总页数, 可见页数, 页面点击事件: 获得当前页面

          $(".pagination").twbsPagination(

            totalPages: 100,

            visiblePages: 5,  

            onPageClick: function(event, page){

              currentPage = page;

            }

          );

        }

      }

    })

  </script>

以上是关于template and pagination的主要内容,如果未能解决你的问题,请参考以下文章

template and pagination

Django templates and models

Enum, Generic and Templates

Part 35 AngularJS caseInsensitiveMatch and Inline Templates

$.ajax get and post template

HLS Coding Style: C++ Classes and Templates