处理mustache.js循环中的数据块

时间:2015-03-25 18:00:50

标签: javascript mustache

我想有可能有一种更好的方法来处理服务器上的数据或者可能通过分页但是我想知道是否有办法直接处理mustache.js块中的循环?

我想我试图找到与array_chunk对数组php的行为类似的行为。

我在与此相关的文档中找不到任何内容。

我正在使用基础网格,并希望每行显示三(3)列,这就是目标(无需触及服务器上的数据)。

提前致谢!

小胡子模板

<script id="feeds-list" type="text/template">

    {{#feeds}} // in chunks of 3 please!   
        <div class="row">   
            <div class="large-4 medium-4 columns">
                <div class="panel">
                    {{title}}
                    {{!link}}
                    {{!description}}
                    {{!guid}}
                    {{!enclosure}}
                    {{!pubDate}}
                </div>
            </div>
        </div>       
    {{/feeds}}

</script>

供参考

<script>
var SITE_URL = "<?php echo site_url();?>";

(function($){        
    var Feeds = {
        options : {
            cache : false,
            url   : SITE_URL + '/welcome/getData',
            type : 'GET',
            dataType : 'json'
        },
        init : function(){
            this.doAjax().then(
                $.proxy(this.handleResponse, this),
                $.proxy(this.handleErrors, this)
            );
        },
        doAjax : function(){
            return $.ajax(this.options).promise();
        },
        handleResponse : function(response){

            var template = $("#feeds-list").html();
            var html     = Mustache.to_html(template, $.parseJSON(response));

            $("#feeds").html(html).hide().fadeIn(500);

        },
        handleErrors : function(error){
            switch(error.status)
            {
                case 401:
                    alert('You do not have the proper credentials to access this page');
                break;
            }
        }

    };

    Feeds.init();

}(jQuery));    
</script>

0 个答案:

没有答案