Fácil de usar jsrender motor de plantillas

1, descarga jsrender.js
Aquí Insertar imagen Descripción
2, fácil de usar

Página en:

 <table>
  <thead>
     <tr>
       <th >序号</th>
       <th>评论</th>
     </tr>
   </thead>
   <tbody>
   <!--模板渲染的位置-->
   </tbody>
 </table>

Uso motor de plantillas

<!-- 引入模板引擎 -->
  <script src="/static/assets/vendors/jsrender/jsrender.js"></script>
<!-- 使用模板引擎 -->
  <script id="comments_tmpl" type="text/x-jsrender">
    {{for comments}}
      <tr>
        <td>{{:#index}}</td>
        <td>{{:content}}</td>
      </tr>
    {{/for}}
  </script>

petición AJAX para obtener los datos y enviar a la lista rendido

    $.getJSON('/admin/api/comments.php',{},function(res){
      var html=$('#comments_tmpl').render({
        comments:res
      })
      //将数据渲染到页面上
     $('tbody').html(html)
    })
Publicado 43 artículos originales · ganado elogios 1 · vistas 3127

Supongo que te gusta

Origin blog.csdn.net/u011523953/article/details/104551060
Recomendado
Clasificación