2011-03-06 3 views
1

문제 설명이 명확 해 지도록 코드 조각으로 시작합니다.메모리에서 dijit (dojo) 트리를 완전히 지우고 자리 표시자를 지우십시오.

:
  • <div id="center" class="column" dojoType="dijit.layout.TabContainer">

    <div id="first" dojoType="dijit.layout.ContentPane" title="first" selected="true"> 
    
        <div id="first_content"></div> 
    
    </div> 
    
    <div id="second" dojoType="dijit.layout.ContentPane" title="second"> 
    
        <div id="second_content"></div> 
    
    </div> 
    

    </div>

  • 내가 HTML로는 Dijit 나무를로드하는 자바 스크립트 기능이 :

    1. I는 HTML 코드의 조각을 가지고

    ,

    기능 부하()

    { 
    //load data 
    dojo.xhrGet(firsthierarchy("first_content", "file1.json")); 
    dojo.xhrGet(secondhierarchy("second_content", "file2.json")); 
    } 
    
    function firsthierarchy(node, url){ 
    return { 
    url: url, 
    node: dojo.byId(node), 
    handleAs: "json", 
    load: loadfirsthierarchy 
    }; 
    } 
    
    function secondhierarchy(node, url){ 
    return { 
    url: url, 
    node: dojo.byId(node), 
    handleAs: "json", 
    load: loadsecondhierarchy 
    }; 
    } 
    
    function loadfirsthierarchy(data, xhr) 
    { 
    if(xhr.args.node) 
    { 
    store1 = new dojo.data.ItemFileWriteStore({data: data}); 
    treeModel1 = new dijit.tree.ForestStoreModel({ 
    store: store1, 
    query: { 
    "type": "continent" 
    }, 
    rootId: "root", 
    rootLabel: "Continents", 
    childrenAttrs: ["children"] 
    }); 
    tree1 = new dijit.Tree({ 
         model: treeModel1, 
        },xhr.args.node.id); 
    } 
    } 
    
    function loadsecondhierarchy(data, xhr) 
    { 
    if(xhr.args.node) 
    { 
    store2 = new dojo.data.ItemFileWriteStore({data: data}); 
    treeModel2 = new dijit.tree.ForestStoreModel({ 
    store: store2, 
    query: { 
    "type": "continent" 
    }, 
    rootId: "root", 
    rootLabel: "Continents", 
    childrenAttrs: ["children"] 
    }); 
    
    tree2 = new dijit.Tree({ 
    model: treeModel2, 
    },xhr.args.node.id); 
    } 
    } 
    

    상기 기능 모두 잘 작동된다. 이제는 "first_content"및 "second_content"div에있는 기존 트리를 지우고 해당 div를 새로운 내용의 새 트리로로드 할 수있는 재설정 기능을 원합니다. 예 :

    기능 리셋()

    { 
    // here I want to completely wipe out the exiting trees in all of the dojo contentpanes. 
    // And I want to load the contentpanes with entire new set of data. 
    // Maybe like : 
    // dojo.xhrGet(firsthierarchy("first_content", "file3.json")); 
    // dojo.xhrGet(secondhierarchy("first_content", "file4.json")); 
    } 
    

    나는 리셋 기능을 구현하는 방법에 대한 아무 생각이 없습니다. 나에게 단서를 제공해 주시겠습니까? 트릭

    나는이 작업을 수행 할 것입니다 방법을 수행해야합니다

    reset: function() { 
        myTree.destroyRecursive(); 
        myTreeModel.destroyRecursive(); // I'm not 100% sure you need this, destroying the tree may do this automatically 
        delete myStore 
    } 
    

    이 도장을 사용하여 모듈을 만드는 것입니다 :로

    답변

    0

    트리에 대한 참조를 유지 treeModel에 저장은 다음 함수를 정의 .provide는 TreeWrapper()으로, 트리 수명주기 (데이터 가져 오기, 트리 만들기, 트리 삭제)를 처리합니다. 이 래퍼 모듈은 위의 리셋 함수를 가지며 모든 다른 변수에 대한 참조를 포함 할 수 있습니다.

    트리에 대해 갖고있는 모든 dojo.subscribe도 추적해야하며 탈퇴해야합니다.

    관련 문제