zysyyz / jquery-option-tree

Automatically exported from code.google.com/p/jquery-option-tree
0 stars 0 forks source link

Tree is indexed by option value: empty labels #10

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
When tree is indexed by option value, labels in the first select are empty. Why?

Below my test:

var options = {
  set_value_on: 'each',
  indexed: true
};

$.getJSON('ajax/category.json', function(tree) {
  $('input[name=demo1]').optionTree(tree, options);
});

ajax/category.json:
{
  "2004": {"08": "2004-08"},
  "2005": {"04" : "2005-01", "07" : "2005-02"}
}

Original issue reported on code.google.com by samuele....@gmail.com on 26 Mar 2012 at 4:55

GoogleCodeExporter commented 8 years ago
The json you presented is not valid for index:true mode. 

As per documentation, when using indexed: true mode:
// Option VALUES are property names. Property values become option names. 
// Additional levels have be loaded dynamically using 'on_each_change' option.

JSON loaded in indexed: true should only be one-level deep. To load multiple 
levels at once, you need to use indexed:false mode. In your case, you'd need to 
use the same JSON, but reverse the 2nd level like so:

ajax/category.json:
{
  "2004": {"2004-08": "08"},
  "2005": {"2005-01": "04" , "2005-02": "07"}
}

Original comment by kkotowicz on 26 Mar 2012 at 5:30