见。 JQuery AP docs 基本使用模板。
我写了这一功能的延伸,使多个类别得以分类。
$(
JQuery template).tmpl_sort(
data,
[options,
] array of groups)
• For JQuery template, data and options, see the tmpl API documentation.
• array of groups should be an array consisting of strings which identify the groups.
法典:
(function($){
$.fn.tmpl_sort = function(data, options_or_groups, array_groups){
return $.tmpl_sort(this, data, options_or_groups, array_groups);
}
$.tmpl_sort = function(template, data, options_or_groups, array_groups){
if(typeof array_groups == "undefined"){
array_groups = options_or_groups;
options_or_groups = void 0;
}
array_groups = typeof array_groups == "string" || typeof array_groups == "number" ? [array_groups] : array_groups;
if(!(array_groups instanceof Array)) throw new TypeError("$.fn.tmpl_sort: second argument has to be a string or array");
var groups = {};
for(var i=0; i<array_groups.length; i++){
(function(groupname){
var last;
groups[groupname] = function(group){
/* === is a strict comparison operator */
return last === (last=group);
}
})(array_groups[i]);
}
return template.tmpl(data, groups, options_or_groups)
}
})(jQuery);
www.un.org/Depts/DGACM/index_spanish.htm http://jsfiddle.net/gBTzU/“rel=“nofollow” http://jsfiddle.net/gBTzU/。
var Leagues = [
{ League: 1, Group: "A", Team: "France" },
{ League: 1, Group: "A", Team: "China" },
{ League: 1, Group: "B", Team: "Brazil" },
{ League: 2, Group: "A", Team: "England" },
{ League: 2, Group: "A", Team: "Scotland" },
{ League: 2, Group: "B", Team: "India" }
];
$("#itemtemplate").tmpl_sort(Leagues, ["sameleague", "samegroup"]).appendTo("#lvList");