English 中文(简体)
在多个团体的支持下履行分类职能
原标题:jquery tmpl grouping function with support for multiple groups

在有人试图这样做的情况下,可以找到任何实例,说明如何利用jquery tmpl(jquery tmpl()进行分类,这样,我就把我所带的(这些作品)放在了后面。

最佳回答

。 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");
问题回答
<!DOCTYPE html>
<html>
<head>
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script>
    <style type="text/css">
        #lvList { float:left; }
        .league { background-color: #E8F6FF; }
        .group { background-color: #FEEAEB; margin-left: 10px; }
        .team { margin-left: 20px; }
    </style>
</head>
<body>
    <script id="itemtemplate" type="text/x-jquery-tmpl"> 
        {{if !$item.sameasbefore("League") }}
            <div class="league">League: ${League}</div>
        {{/if}}
        {{if !$item.sameasbefore("Group") }}
            <div class="group">Group: ${Group}</div>
        {{/if}}
        <div class="team">${Team}</div>
    </script>

    <div id="lvList"></div>

    <script type="text/javascript">
        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" }
        ];

    var grouping = [];
    $("#itemtemplate").tmpl(Leagues, {
        sameasbefore: function (field) {
            var same = false;
            if (grouping[field] === this.data[field])
                same = true;
            grouping[field] = this.data[field];
            return same;
        }
    }).appendTo("#lvList");

    </script>
</body>
</html>




相关问题
wpf-DragDrop in a listbox with groupstyle

I am using the control library from http://code.google.com/p/gong-wpf-dragdrop/successfully for my listbox dragging operation.But there is an issue when i drop an item to a listbox with a group style....

Combine pairs to groups [PHP / Arrays]

I have pairs of items in an PHP array. Example: <?php $elements = array( tiger => lion , car => bike , lion => zoo , truck => plane ); ?> Now I want to combine ...

LINQ Merging results in rows

I have a LINQ query which returns a set of rows. The structure is: NAME, col1, col2, col3, col4 name1 1 null null null name1 null 1 null null name1 null null 1 1 As a ...

How to group items by date range in XSLT?

I have a bunch of data that looks a little like this: <item> <colour>Red</colour> <date_created>2009-10-10 12:01:55</date_created> <date_sold>2009-10-20 22:...

Self-Joins, Cross-Joins and Grouping

I ve got a table of temperature samples over time from several sources and I want to find the minimum, maximum, and average temperatures across all sources at set time intervals. At first glance this ...

Grouping with SubSonic 3

I have the following table "GroupPriority": Id Group Priority 1 1 0 2 2 0 3 3 0 4 2 1 5 1 1 6 2 2 7 ...

热门标签