Как мы можем установить детей в dojo TreeGrid?

когда я использую LazyTreeGrid, я столкнулся с небольшой проблемой; У меня есть файл JSON следующим образом:

{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'] (к сожалению, это не работает...)?


person Smile-Yuhao    schedule 04.04.2016    source источник


Ответы (2)


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

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

Это отлично работает для меня.

person Smile-Yuhao    schedule 05.04.2016

У меня была такая же проблема с файлом Json и обычным деревом отложенной загрузки.

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

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 с другого сервера, но, возможно, он будет работать аналогично!

Привет,

Алекс

person Community    schedule 07.04.2016
comment
Спасибо Алекс, проблема в том, что дети не на следующем уровне (в description.compents). Поэтому я решил эту проблему с помощью onComplete( item.dataDescription.components ); :) - person Smile-Yuhao; 08.04.2016