> „ > >

laytpl jsģ

Wվ݋ 2020-03-14 21:32 / ھWվO / g
ļ
<script src="../js/laytpl.js"></script>
//һģʹһscript˺ģ磺
<script id="demo" type="text/html">
  <h3>{{ d.title }}</h3>
  <ul>
  {{#  layui.each(d.list, function(index, item){ }}
    <li>
      <span>{{ item.modname }}</span>
      <span>{{ item.alias }}</span>
      <span>{{ item.site || '' }}</span>
    </li>
  {{#  }); }}
  {{#  if(d.list.length === 0){ }}
    o
  {{#  } }} 
  </ul>
</script>
 
//ڶҕDڳʬFȾY
<div id="view"></div>
 
//Ⱦģ
var data = { //
  "title":"LayuiģK"
  ,"list":[{"modname":"","alias":"layer","site":"layer.layui.com"},{"modname":"","alias":"form"}]
}
var getTpl = demo.innerHTML
,view = document.getElementById('view');
laytpl(getTpl).render(data, function(html){
  view.innerHTML = html;
});
ŷzoozݽ_ŷ̫Ƭ_ŷձһ