JavaScript & jQuery Code Snippet

1. 按照每个object的Name属性对object对象集合进行排序;

            //sort a collection of objects by Name property
            function sortByItemName(originalObjects) {
                var options = {};

                $.each(originalObjects, function (index, item) {
                    options[item.Name] = item;
                });
                //sort() is case sensitive by default
                var keys = Object.keys(options).sort(function (a, b) {
                    return a.toLowerCase().localeCompare(b.toLowerCase());
                });

                //get the results after sort
                var sortedObjects = {};
                $.each(keys, function (i, key) {
                    sortedObjects[i] = options[key];
                });
                return sortedObjects;
            }

2. 

你可能感兴趣的:(JavaScript & jQuery Code Snippet)