Select2 with nested array working, but some values are bold and not selectable.

417 views
Skip to first unread message

rvd...@gmail.com

unread,
Jul 9, 2015, 7:00:04 AM7/9/15
to sel...@googlegroups.com
Hey guys,

I'm using select2 to display a nested array, which works just fine. Except for when the array values have children.

They then become bold and not selectable. This is my code.

//JQUERY 1.9

(function($){
$(document).ready(function() {
$.get('/classes/categories.php?do=buildtree&output=select2', function(treedata) {

datajson = $.parseJSON(treedata);

$(".select2productgroups").select2({
data: datajson,
placeholder: "Select a category",
});
});
});
})(jq)

This is my array generated by PHP (treedata)

[
{
"id": "0",
"text": "ALL PRODUCTS"
},
{
"id": "3",
"text": "PC Onderdelen",
"children": [
{
"id": "6",
"text": "Moederborden",
"children": [
{
"id": "7",
"text": "Midi Towers"
}
]
},
{
"id": "4",
"text": "Processoren",
"children": [
{
"id": "17",
"text": "moederbordensub"
}
]
},
{
"id": "8",
"text": "Laptops"
},
{
"id": "9",
"text": "Muizen",
"children": [
{
"id": "10",
"text": "Draadloos"
}
]
},
{
"id": "18",
"text": "Test categorie"
}
]
},
{
"id": "14",
"text": "Rootcat3"
},
{
"id": "19",
"text": "Inkt",
"children": [
{
"id": "20",
"text": "subname",
"children": [
{
"id": "27",
"text": "HP Inkt"
}
]
}
]
}
]

All groups have id, which is required to select them.

Can someone point me in the right direction, in order to be able to select 'PC onderdelen' for example.

Thanks! Roy

Kevin Brown

unread,
Jul 9, 2015, 12:00:14 PM7/9/15
to sel...@googlegroups.com
You can read the reasoning for not allowing selectable headers in 4.0.0 here: http://stackoverflow.com/q/30405664/359284

And a possible solution for it here: http://stackoverflow.com/q/30820215/359284

--
You received this message because you are subscribed to the Google Groups "select2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to select2+u...@googlegroups.com.
To post to this group, send email to sel...@googlegroups.com.
Visit this group at http://groups.google.com/group/select2.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages