Tree_3

3304 단어 htmlJ#dojo
<div dojoType="dojo.data.ItemFileWriteStore" jsId="myStore" id="treeDemo"></div>  <!--       -->
	<div dojoType="dijit.tree.TreeStoreModel" jsId="catModel" store="myStore" query="{id: '0'}"></div><!--          -->
	<div id="collectionsTree" data-dojo-type="dijit.Tree" data-dojo-props='"class":"container", model:catModel,......></div><!--        -->

dojo.data.ItemFileWriteStore는 파일을 읽는 클래스이지만 데이터 속성을 설정할 수 있습니다. 효과는 같습니다.
//     data  
	var itemsArr = [{
	                  id : '0',       
	                name : '   ',
			  department : 'w3',
			        root : true,
				   level : 1,
			    children : [{_reference: '1'}, {_reference: '2'},{_reference: '3'}]
	               },{ 
				      id : '1', 
				    name : '  1',
		      department : '   ',
					level : 2,
			    children : [{_reference: '4'},{_reference: '5'}]
				   },{ 
				      id : '4',
					name : '   ',
			  department : '   ',
				level : 3
				   },{ 
				      id : '5',
					name : '   ',
			  department : '   ',
			  level : 3
			       },{ 
				      id : '2', 
					name : '   ',
			  department : '   ',
					 level : 3
			       },{ 
				      id : '3',
					name : '   ',
			  department : '   ',
					 level : 3
			       }];
    

   
    //        
    var treeData = function(items){
	    this._identifier = 'id';
		this._label = 'name';
		this._items = items;
		this.getData = function(){
		    var s = "{";
			    s += "identifier:'" + this._identifier + "',";
				s += "label:'" + this._label + "',";
				s += "items:[";
			for(var i = 0, len = this._items.length; i < len; i++){
			    s += "{id:'" + this._items[i].id  + "',";
				s += "name:'" + this._items[i].name + "',";
				s += "department:'" + this._items[i].department + "',";
				s += "level:" + this._items[i].level + "";
				if(!!this._items[i].children){
				   s += ",children : [";
				   var cs = this._items[i].children;
				   for(var j = 0, jLen = cs.length; j < jLen; j++){
				       s += "{_reference:'" + cs[j]._reference + (j == (jLen-1) ? "'}]" : "'},");
				   } 
				}
				s += (i == (len-1) ? "}" : "},");
			}
			s += "]}";
			return s;
		};
	}
    

        //   dojo.data.ItemFileWriteStore       .
	document.getElementById("treeDemo").setAttribute("data", new treeData(itemsArr).getData());
 

좋은 웹페이지 즐겨찾기