jquery - How can I create a Directory listing that sorts each first letter of a item to a letter-group with javascript -


i trying create directory listing looks this:

users can add items, lets if user add o-item-1 big letter of "o" should generated , item should inside element , if more items start same letter should added in same o-letter group.

i using webservice data , looks this:

this container append data to:

<div class="listitem-section-template">  </div> 

this how fill container data @ moment:

<script id="listitem-template" type="text/html"> <div class="listitem-section-section">         <div class="listitem-section-title">a</div> <-- hardcoded            <div class="listitem-section-container">             <div class="listitem-section-item">                 <div class="listitem-section-item-title">                     <a href="{{= url}}" >{{= title}}</a>                    </div>                     </div>             </div>     </div>     <div class="processlinks-line"></div> </script> 

this function , how fill data:

 get: function(web) {             ast.utils.json.get(_sppagecontextinfo.webserverrelativeurl+"/_vti_bin/ast/listitem/listitemservice.svc/getlistitem", null, ast.listitem.renderlistitem);         }, renderlistitem: function(data) {             $("#listitem-template").tmpl(data["listitemresults"]).prependto(".listitem-section-template");     } 

and far have done this:

<script type="text/javascript">     var filter = new array();     filter["#"] = "09"; //for numbers     filter["a"] = "a";     filter["b"] = "b";     filter["c"] = "c";     filter["d"] = "d";     filter["e"] = "e";     filter["f"] = "f";     filter["g"] = "g";     filter["h"] = "h";     filter["i"] = "i";     filter["j"] = "j";     filter["k"] = "k";     filter["l"] = "l";     filter["m"] = "m";     filter["n"] = "n";     filter["o"] = "o";     filter["p"] = "p";     filter["q"] = "q";     filter["r"] = "r";     filter["s"] = "s";     filter["t"] = "t";     filter["u"] = "u";     filter["v"] = "v";     filter["w"] = "w";     filter["x"] = "x";     filter["y"] = "y";     filter["z"] = "z";     filter["Å"] = "aa";     filter["Ä"] = "ae";     filter["Ö"] = "oe";      $(document).ready(function () {         icc.processdocumentlinks.get();      }); </script>  

i thinkin of creating selectors using array , have them hidden:

<div id="listitem-section-section-#" class="listitem-section hidden-section">..</div> <div id="listitem-section-section-a" class="listitem-section hidden-section">..</div>  <div id="listitem-section-section-b" class="listitem-section hidden-section">..</div> <div id="listitem-section-section-c" class="listitem-section hidden-section">..</div> etc..  

and fill items inside if first letter match selectors , show it?

anyone have tips or guidance on how can accomplish in smooth way?

any kind of appreciated!

try this! http://jsbin.com/amelaba/1/edit

<div class="letter-list"> </div>  <button>add new</button>  <script>  $('button').click(function () {     var title = prompt("enter name:");     if (!title.length) return;     var letter = title.substr(0, 1).tolowercase();      var list = $('.letter-list');     var section = list.children('[data-letter="'+letter+'"]');     if (!section.length) {         var section = $('<div data-letter="'+letter+'"></div>');         if (!list.children().length) {             list.append(section);         } else {             // find right element list sorted             section.insertafter(list.children()[0]);         }     }      var item = $('<span>'+title+'</span>');     if (!section.children().length) {         section.append(item);     } else {         // find right element list sorted         item.insertafter(section.children()[0]);     }  });  </script>  <style>     .letter-list {         width:200px;         min-height:100px;         background:#eef;         margin:20px auto;         padding:10px;     }     [data-letter] {         background:#efe;         margin:7px;     }     [data-letter]:before {         content:attr(data-letter);         font-size:30px;         margin:7px;         float:left;     }     span {         display:block;     } </style> 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -