juicer 语法

${ 变量 }

处于安全角度考虑 ${ 变量 } 会对内容进行转义 $${ 变量 }避免转义

${ _ } 常用于数据源为数组的情况 _ 为对数据源的引用

${@each} ...{@/each}  循环

${@if}...{@else if}...{@else}...{@/if}

${varname | function }

{# 注释内容}

自定义函数

var json = {

  links: [

    { href: 'http://juicer.name' , alt: 'Juicer'},

    { href: 'http://benben.cc', alt: 'Benben'},

    {href: 'http://ued.taobao.com', alt: 'Taobao UED'}  

  ]

};

var tpl = [

  '{@each links as item}',

    '${item|links_build} <br />',

  '{@/each}'

].join(' ');

var links = function(data) {

  return '<a href=" ' + data.href + ' " alt=" ' + data.alt +  ' ">';

}

juicer.register('links_build', links);

juicer(tpl, json);

html 中的模版 和javascript 有相应的对应关系

/*********************************************/

  框架里的 tr 的id <tr id="object_object->id">

  在juicer 进行数据绑定

  <script type="text/template" id="product_channel_tpl">

    <tr id="product_channel_${product_channel.id}">

    ....    

  </script>

/********************************************/

原文地址:https://www.cnblogs.com/hiraeth/p/8568899.html