当前位置: 代码迷 >> Web前端 >> mustache例证(2)
  详细解决方案

mustache例证(2)

热度:167   发布时间:2013-10-19 20:58:23.0
mustache例子(2)

Mustache例子

以下代码都是js中

//format函数不理解  希望看到此文的给我解释一下format函数

//format函数的作用是:假设artcatgor为数组 var artcatgor = [白色,6,红色,4,黄色,10,绿色,3,灰色,13]  数组调用format之后的效果变为

白色(6)

红色(4)

黄色(10)

绿色(3)

灰色(13)

//漂亮的将数组中的元素整齐的呈现出来

var itemCount=0;
function format(){
return function(text, render) {
itemCount++;
if (itemCount % 2 == 1) {
return '<li><a href="javascript:void(0)" onclick="selectFacets(\''
+ this
+ '\')">'
+ this;
} else {
return "&nbsp;(" + this + ")</a></li>";
}
};
}


function processSearchResult() {

var data = {

"artcatgory" : artcatgory,    //artcatgory为数组
"items" : priceLst,              //priceLst为数组
"dateList" : dateList,         //dateList为数组
"format" : format,              //三个数组调用format函数

};

    //价格导航显示 
var template=$("#price_list").html();
var outputprice = Mustache.render(template, data);
$("#pricebanner").html(outputprice);

}




  相关解决方案