ruby on rails - Select2 nested json parsing not working Rails3 -


i'm trying make select2 working ajax loaded json data nested attributes. wanna http://ivaynberg.github.io/select2/#multi.

eaxmple json:

[{   id: 1,   name: "groupname",   users: [{id: 1, name: 'username'}, {id: 2, name: 'seconduser}]  }] 

on site use <optgroup label="groupname"><option value="1">username</opyion></optgroup> , getting right result.

in case displays nesting properly, can select groupname, need select nested username , make grouoname unselectable, gor informational purposes.

code:

$('#user_tokens').select2({   placeholder: "search user",   minimuminputlength: 0,   tags: true,   multiple: true,   ajax: {     url: "messages/users_data.json",     datatype: 'json',     quietmillis: 100,     data:  function(search, page) {       return {         q: search,         per: 3,         page: page       };     },     results: function(data, page) {       return {          results: data,          };     }   },   formatresult: formatresult,   formatselection: formatselection,   dropdowncssclass: "bigdrop" }); 

formatresult:

   var formatuserresult = function(data) {      var optgroup = "";      var users = "";        if (data.name !== undefined) {          data.users.foreach(function(e) {            users += "<li class='select2-results-dept-1 select2-result select2-result-    selectable'>" +             "<div class='select2-result-label'>" +              "<span class='select2-match'></span>"+              e.firstname +            "</div>" +          "</li>";          });          optgroup += "<div class='select2-result-label'>" +           "<span class='select2-match'></span>" +           data.name + "</div>" +          '<ul class="select2-result-sub">' + users + '</ul>';        }        return optgroup;      } 

the problem optgroup must have class: 'select2-result-unselectable' dunno it.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -