开发者

Jquery Templeate, dropping last item off in the each

Currently I am using jquery templating with some json data, I have a couple images that I am getting and I would like to drop the last image that I am getting from my json data. Right now I have this coded ( this only a snippet of the spot I am having the problem at):

    <div class="altViews">
    <ul class="clearfix">
    {{each(i,addImage) AdditionalImages}}
        <li class="altImage">
            <img src="http://im开发者_如何学Cages.url.com/images/products/${addImage}" alt="${Name}" id="${addImage}"/>
        </li>
        {{/each}}
    </ul>
</div>

SO the main help I need is to be able to drop the last li, I just dont know how to use my index to do that.


use an {{if}} statement:

<div class="altViews">
    <ul class="clearfix">
    {{each(i,addImage) AdditionalImages}}
        {{if i < AdditionalImages.length - 2}}
        <li class="altImage">
            <img src="http://images.url.com/images/products/${addImage}" alt="${Name}" id="${addImage}"/>
        </li>
        {{/if}}
    {{/each}}
    </ul>
</div>


Another solution:

{{each AdditionalImages}}
    {{if (($index + 1) < AdditionalImages.length)}}
        <li class="altImage">
                    <img src="http://images.url.com/images/products/${addImage}" alt="${Name}" id="${addImage}"/>
        </li>
    {{/if}}
{{/each}}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜