How to update dojo tree data dynamically

后端 未结 7 913
隐瞒了意图╮
隐瞒了意图╮ 2021-02-04 14:39

I would like to know how ot update the data of the dojo.dijit.tree component dynamically. At the moment I\'m creating the tree using dojo.data.ItemFileReadStore and dijit.tree.F

7条回答
  •  名媛妹妹
    2021-02-04 15:15

    Explicitly you "can't", but that doesn't mean you can't hack things to pieces and die trying.

    refreshTree : function(){
        dijit.byId("myTree").dndController.selectNone(); // As per the answer below     
        // Credit to this discussion: http://mail.dojotoolkit.org/pipermail/dojo-interest/2010-April/045180.html
        // Close the store (So that the store will do a new fetch()).
        dijit.byId("myTree").model.store.clearOnClose = true;
        dijit.byId("myTree").model.store.close();
    
        // Completely delete every node from the dijit.Tree     
        dijit.byId("myTree")._itemNodesMap = {};
        dijit.byId("myTree").rootNode.state = "UNCHECKED";
        dijit.byId("myTree").model.root.children = null;
    
        // Destroy the widget
        dijit.byId("myTree").rootNode.destroyRecursive();
    
        // Recreate the model, (with the model again)
        dijit.byId("myTree").model.constructor(dijit.byId("myTree").model)
    
        // Rebuild the tree
        dijit.byId("myTree").postMixInProperties();
        dijit.byId("myTree")._load();
    
    },
    

    This will refresh your Tree.

提交回复
热议问题