artTemplate4.0使用总结以及与JSP页面冲突解决方案

2017-12-01  本文已影响0人  李胖醒
2524989571-599d548e962c9_articlex.png
<script id="card" type="text/html" >
     {{each articles as data index}}
        {{if data.style_type == 1}}
         <!-- 左文右图 -->
                <div class="card s6" name="{{ data.url }}>">
                    <a href="{{ data.url }}">
                        <div class="card_middle">
                            <div class="card_right">
                                <h3 class="news-title">{{ data.title }}</h3>
                                 <p class="news-info">
                                     <span class="news_source">{{  data.source_name  }}</span>
                                     <span class="news_time">{{ $imports.formatDate(data.publish_time)  }}</span>
                                     <span class="news_comment">{{ data.comment_count }}条评论</span>
                                 </p>
                            </div>
                            <div class="card_right_img">
                                <img class="lazy" data-url="{{ $imports.crop( data.thumbnails[0].url,2,400,330) }}"  alt="" />
                            </div>
                        </div>                                          
                    </a>
                </div>
            {{ else if data.style_type == 2 }}
            <!-- 视频 -->
                <div class="card s3" name="{{ data.url }}">
                        <a href="javascript:void(0)">
                            <div class="video_container">
                                <div class="video_img">
                                    <div class="video_mask">
                                        <h3 class="dotdot line3">{{ data.title }}</h3>
                                    </div>  
                                        <span class="play-btn" name="{{ data.videos[0].video_src }}"></span>
                                        <img  class="lazy" data-url="{{ data.thumbnails[0].url }}"  alt="" />
                                </div>
                                <video style="visibility:hidden;" controls="" poster="{{ data.thumbnails[0].url }}"></video>
                            </div>
                             <p class="news-info">
                                <span class="news_source">{{  data.source_name  }}</span>
                                <span class="news_time">{{ $imports.formatDate(data.publish_time)  }}</span>
                                <span class="news_comment">{{ data.comment_count }}条评论</span>
                            </p>
                        </a>
                </div>          
        {{ /if }}
     {{/each}}
</script>
3383803729-599d64f394724_articlex.png

// 定义模板方法
template.defaults.imports.formatDate = function(time) {
    return G.formatDate(time)
}
template.defaults.imports.crop = function(src,type,w,h) {
    return G.crop(src,type,w,h)
}
4.0之前用的是这种方式
template.helper('formatPrice', function(price, type) {});
上面的例子中要调用此函数需要通过imports方法注册:
上一篇 下一篇

猜你喜欢

热点阅读