1

, когда я использую LazyTreeGrid, я встретил небольшую проблему; У меня есть файл JSON как это:Как мы можем установить детей в dojo TreeGrid?

{id: 'AF', name:'Africa',description:""}, 
{id: 'EG', name:'Egypt',description:""}, 
{id: 'KE', name:'Kenya',description: 
{ 
    compents: 
    [ 
    {id: 'Nairobi', name:'Nairobi', type:'city'}, 
    {id: 'Mombasa', name:'Mombasa', type:'city'} 
    ]  
} 
} 

я не имею ни малейшего представления о том, как установить детей в ForestStoreModel, может быть, как childrenAttrs:['description.compents'] (к сожалению, это не работает ...)?

ответ

0

Я нашел одно решение, мы можем использовать onComplete как этот

var model = new ForestStoreModel({ 
    getChildren : function (item, onComplete, onError) { 
     onComplete(item.dataDescription.components); 
     } 
}); 

Это прекрасно работает для меня.

0

У меня была такая же проблема с Json File и обычным lazyloading Tree.

Чтобы получить детей, идентификатор сделал это, как этот

var restStore = new JsonRest 
    ({ 
     target: "http://localhost........", 
     headers: { 'Content-Type': 'application/json;charset=utf-8' } 
    }); 

    // Get an object by identity, then the remaining code will be executed (because of the async) 
    // Otherwise the remaining code will be executed, before we get the object from the server (it wouldn't work) 
    restStore.get("").then(function(items) 
    { 
     // set up a local store to get the tree data, plus define the method 
     // to query the children of a node 
     var MemoryStore = new Memory 
     ({ 
      data: items, 
      getChildren: function(object) 
      { 
       return this.query({parent: object.id}); 
      } 
     }); 

Я не знаю, если у вас есть, чтобы получить файл в формате JSON с другого сервера, но, возможно, он будет работать аналогично!

Привет,

Alex

+0

Спасибо Алекс, проблема заключается в том, что дети не в следующем уровне (в 'description.compents'). Поэтому я решил эту проблему с помощью 'onComplete (item.dataDescription.components);' :) –

+0

Ahh, ладно, я понял. Проблема решена, отлично! :-) –