2016-06-09 2 views
0

У меня есть дерево Dojo, и я пытаюсь добавить узел в конец. Я попытался обновить хранилище ниже кода. Хотя магазин, обновленный по дереву, не показывал новый узел.Добавить узел в дерево Dojo

this.virtualtree.model.store.put({type:"form",parent:"wpRoot",id:"ABC",name:"ABC"}); 

Позже я попытался использовать функцию PasteItem на модели. Ниже приведен код. Тем не менее он не работает.

this.virtualtree.model.pasteItem({"type":"form","parent":"wpRoot","id":"ABC","name":"ABC"},window._self.virtualtree.model.root,window._self.virtualtree.model.root,true,9,true); 

Пожалуйста, дайте мне знать, как изменить дерево.

ответ

1

Вы должны использовать dojo/store/Observable в сочетании с store.add()
взглянуть на додзё онлайн документации: https://dojotoolkit.org/reference-guide/1.10/dijit/Tree.html#id7

И смотрите ниже рабочего примера:

require([ 
 
    "dojo/_base/window", "dojo/store/Memory", "dojo/store/Observable", 
 
    "dijit/tree/ObjectStoreModel", "dijit/Tree", 
 
    "dojo/domReady!" 
 
], function(win, Memory, Observable, ObjectStoreModel, Tree){ 
 

 
    // Create test store, adding the getChildren() method required by ObjectStoreModel 
 
    var myStore = new Memory({ 
 
     data: [ 
 
      { id: 'world', name:'The earth', type:'planet', population: '6 billion'}, 
 
      { id: 'AF', name:'Africa', type:'continent', population:'900 million', area: '30,221,532 sq km', 
 
        timezone: '-1 UTC to +4 UTC', parent: 'world'}, 
 
       { id: 'EG', name:'Egypt', type:'country', parent: 'AF' }, 
 
       { id: 'KE', name:'Kenya', type:'country', parent: 'AF' }, 
 
        { id: 'Nairobi', name:'Nairobi', type:'city', parent: 'KE' }, 
 
        { id: 'Mombasa', name:'Mombasa', type:'city', parent: 'KE' }, 
 
       { id: 'SD', name:'Sudan', type:'country', parent: 'AF' }, 
 
        { id: 'Khartoum', name:'Khartoum', type:'city', parent: 'SD' }, 
 
      { id: 'AS', name:'Asia', type:'continent', parent: 'world' }, 
 
       { id: 'CN', name:'China', type:'country', parent: 'AS' }, 
 
       { id: 'IN', name:'India', type:'country', parent: 'AS' }, 
 
       { id: 'RU', name:'Russia', type:'country', parent: 'AS' }, 
 
       { id: 'MN', name:'Mongolia', type:'country', parent: 'AS' }, 
 
      { id: 'OC', name:'Oceania', type:'continent', population:'21 million', parent: 'world'}, 
 
      { id: 'EU', name:'Europe', type:'continent', parent: 'world' }, 
 
       { id: 'DE', name:'Germany', type:'country', parent: 'EU' }, 
 
       { id: 'FR', name:'France', type:'country', parent: 'EU' }, 
 
       { id: 'ES', name:'Spain', type:'country', parent: 'EU' }, 
 
       { id: 'IT', name:'Italy', type:'country', parent: 'EU' }, 
 
      { id: 'NA', name:'North America', type:'continent', parent: 'world' }, 
 
      { id: 'SA', name:'South America', type:'continent', parent: 'world' } 
 
     ], 
 
     getChildren: function(object){ 
 
      // Add a getChildren() method to store for the data model where 
 
      // children objects point to their parent (aka relational model) 
 
      return this.query({parent: object.id}); 
 
     } 
 
    }); 
 
    myStore = new Observable(myStore); 
 
    // Create the model 
 
    var myModel = new ObjectStoreModel({ 
 
     store: myStore, 
 
     query: {id: 'world'} 
 
    }); 
 

 
    // Create the Tree. 
 
    var tree = new Tree({ 
 
     model: myModel 
 
    }); 
 
    tree.placeAt("test"); 
 
    tree.startup(); 
 
    
 
    myStore.add({id: 'foo', name:'Added after tree creation', type:'continent', parent: 'world'}); 
 
});
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script> 
 
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/resources/dojo.css"> 
 
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dijit/themes/tundra/tundra.css"> 
 

 
<div class="tundra"> 
 
    <div id="test"></div> 
 
</div>

Смежные вопросы