pjekel / cbtree

The Dijit Tree with Multi State Checkboxes, project code 'cbtree' , is a highly configurable dojo/dijit tree with support for multi-state checkboxes or third party widgets capable of presenting a so-called 'checked' state.
Other
75 stars 34 forks source link

idProperty locked to "name" ? #47

Closed apfister closed 10 years ago

apfister commented 10 years ago

trying to use the Heirarchy example with a different attribute for "idProperty" and i only see the root node appear.

edit: using v0.9.4

test data:

var carData = [
              { name:"Cars" ,parent: null , type:"toys", someId: "0" },
              { name:"Audi" ,parent:"Cars", type:"factory", someId: "1" },
              { name:"BMW"  ,parent:"Cars", type:"factory", someId: "2" },
              { name:"A3"   ,parent:"Audi", type:"sedan", someId: "3" },
              { name:"Q7"   ,parent:"Audi", type:"suv", someId: "4" },
              { name:"M3"   ,parent:"BMW" , type:"sedan", someId: "5" },
              { name:"535"  ,parent:"BMW" , type:"sedan", someId: "6" },
              { name:"750"  ,parent:"BMW" , type:"sedan", someId: "7" },
            ];
require(["cbtree/Tree", 
         "cbtree/store/Hierarchy", 
         "cbtree/model/TreeStoreModel"
        ], function (Tree, Hierarchy, TreeStoreModel) {

  var store = new Hierarchy( {data:carData, idProperty:"someId", multiParented:false} );
  var model = new TreeStoreModel( {store:store, query:{type:"toys"}} );
  var tree  = new Tree( {model:model}, "cars-div" );
  tree.startup();
});
pjekel commented 10 years ago

If you change the idProperty you must also change the value of parent. For example, the parent of "Audi" and "BMW" now becomes "0". The parent of "A3" becomes "1":

var carData = [
              { name:"Cars" ,parent: null , type:"toys", someId: "0" },
              { name:"Audi" ,parent:"0", type:"factory", someId: "1" },
              { name:"BMW"  ,parent:"0", type:"factory", someId: "2" },
              { name:"A3"   ,parent:"1", type:"sedan", someId: "3" },
              { name:"Q7"   ,parent:"1", type:"suv", someId: "4" },
              { name:"M3"   ,parent:"2" , type:"sedan", someId: "5" },
              { name:"535"  ,parent:"2" , type:"sedan", someId: "6" },
              { name:"750"  ,parent:"2" , type:"sedan", someId: "7" },
            ];
apfister commented 10 years ago

got it, thanks!