1. 程式人生 > >Juicer自定義函數

Juicer自定義函數

icon sta logs roc 定義 str list 方法 code

首先,先寫自定義的方法:

function (sex) {
    var Max = 2;
    var Min = 1;
    var Range = Max - Min;
    var Rand = Math.random();
    var res = (Min + Math.round(Rand * Range));
    if (sex == ) {
        res = res + 2;
    }
    return res;
}

然後,在juicer裏註冊這個方法。

juicer.register(‘rand‘, app.rand);

最後,在模板裏使用這個方法:

{@each list as it,k}
    {@if k < 10}
        <li class="{@if k > 3} hide {@/if}">
            <div class="city-head">
                <img src="images/touxiang${it.sex|rand}.png" alt="" />
            </div>
            <div class="city-process"
> <div class="city-name"> ${it.name} &nbsp;&nbsp; ${it.tel} </div> <div class="progress progress-striped"> <div class="progress-bar progress-bar-info"
role="progressbar progress-bar-success" aria-valuenow="${it.scale}" aria-valuemin="0" aria-valuemax="100" style="width: ${it.scale}%"></div> </div> </div> <div class="city-km"> ${it.distance}km </div> <div class="clearfix"></div> </li> {@/if} {@/each} <li> <div id="citymore" class="more hidecity" onclick="app.showMoreCitys();">更多詳細信息<i class="icon icon-chevron-down"></i></div> </li>

Juicer自定義函數