Javascript 处理mustache.js循环中的数据块
我想可能有更好的方法来处理服务器上的数据,或者通过分页,但我想知道是否有一种方法可以直接处理Javascript 处理mustache.js循环中的数据块,javascript,mustache,Javascript,Mustache,我想可能有更好的方法来处理服务器上的数据,或者通过分页,但我想知道是否有一种方法可以直接处理mustache.js中的循环 我想我正试图找到类似于array\u chunk对数组php所做的行为 我在文件中找不到与此相关的任何内容 我使用的是foundations网格,希望每行显示三(3)列,这就是目标(不必接触服务器上的数据) 提前谢谢 胡须模板 <script id="feeds-list" type="text/template"> {{#feeds}} // in
mustache.js
中的循环
我想我正试图找到类似于array\u chunk
对数组php
所做的行为
我在文件中找不到与此相关的任何内容
我使用的是foundations网格,希望每行显示三(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>
{{{#feeds}}///请分成三块!
{{title}}
{{!链接}
{{!描述}
{{!guid}
{{!附件}
{{!pubDate}}
{{/feeds}
供参考
<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>
var SITE_URL=“”;
(函数($){
变量源={
选项:{
cache:false,
url:SITE_url+'/welcome/getData',
键入:“GET”,
数据类型:“json”
},
init:function(){
这是doAjax(),然后(
$.proxy(this.handleResponse,this),
$.proxy(this.handleErrors,this)
);
},
doAjax:function(){
返回$.ajax(this.options).promise();
},
HandlerResponse:功能(响应){
var template=$(“#提要列表”).html();
var html=Mustache.to_html(模板,$.parseJSON(响应));
$(“#feeds”).html(html).hide().fadeIn(500);
},
handleErrors:函数(错误){
开关(错误状态)
{
案例401:
警报(“您没有访问此页面的正确凭据”);
打破
}
}
};
Feeds.init();
}(jQuery));