HI
I am using the following cone
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Dijit Tree Test</title>
<style type="text/css">
@import "dojoroot/dojo/resources/dojo.css";
@import "dojoroot/dijit/themes/tundra/tundra.css";
</style>
<script type="text/javascript" src="dojoroot/dojo/dojo.js"
djConfig="parseOnLoad: true, isDebug: true"></script>
<script language="JavaScript" type="text/javascript">
dojo.require("dojo.data.ItemFileWriteStore");
dojo.require("dijit.Declaration");
dojo.require("dijit.Tree");
dojo.require("dijit.form.Button");
dojo.require("dojo.parser");
var items = {};
// scan page for widgets and instantiate them
</script>
</head>
<body class="tundra">
<h1 class="testTitle">Trying the 3rd Time</h1>
<div dojoType="dojo.data.ItemFileWriteStore" jsId="store" url="tree.json"></div>
<div dojoType="dijit.tree.ForestStoreModel" jsId="model" store="store" childrenAttrs="children" labelAttr="name" query="{top:true}">
<script type="dojo/method" event="mayHaveChildren" args="item">
if(item.root){ return true; } // top level
var type = store.getValue(item, "type");
var hasChild = store.getValue(item, "hasChild");
if(top=="root" || hasChild == true)
{ return true;
}
else
{
return false;
}
</script>
<script type="dojo/method" event="getChildren" args="item, onComplete">
//
if(item.root){
return store.fetch({query: {type:'root'}, onComplete: onComplete});
}
else{
var itemtype = store.getValue(item, "type");
//write code for async call here
var pInfo = item ? {parent: item, attribute:"children"} : null;
console.debug(pInfo);
//id: '2',type:'Citrus', hasChild:true, name: 'Orange', children: [ ]
store.newItem({
id: 55,
type: "Citrus",
hasChild: false,
name: "nSomeProperty",
},pInfo);
console.log("item created");
return store.fetch({query: {type :store.getValue(item, "name")}, onComplete: onComplete});
}
//switch(item.root ? "top" : store.getValue(item, "type")){
//case "top":
// return store.fetch({query: {type:'root'}, onComplete: onComplete});
//case "root":
// return store.fetch({query: {type :store.getValue(item, "name")}, onComplete: onComplete});
// }
</script>
</div>
<div dojoType="dijit.Tree" jsId="myTree" id="myTree" model="model" showRoot="false" >
</div>
</body>
</html>
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Dijit Tree Test</title>
<style type="text/css">
@import "dojoroot/dojo/resources/dojo.css";
@import "dojoroot/dijit/themes/tundra/tundra.css";
</style>
<script type="text/javascript" src="dojoroot/dojo/dojo.js"
djConfig="parseOnLoad: true, isDebug: true"></script>
<script language="JavaScript" type="text/javascript">
dojo.require("dojo.data.ItemFileWriteStore");
dojo.require("dijit.Declaration");
dojo.require("dijit.Tree");
dojo.require("dijit.form.Button");
dojo.require("dojo.parser");
var items = {};
// scan page for widgets and instantiate them
</script>
</head>
<body class="tundra">
<h1 class="testTitle">Trying the 3rd Time</h1>
<div dojoType="dojo.data.ItemFileWriteStore" jsId="store" url="tree.json"></div>
<div dojoType="dijit.tree.ForestStoreModel" jsId="model" store="store" childrenAttrs="children" labelAttr="name" query="{top:true}">
<script type="dojo/method" event="mayHaveChildren" args="item">
if(item.root){ return true; } // top level
var type = store.getValue(item, "type");
var hasChild = store.getValue(item, "hasChild");
if(top=="root" || hasChild == true)
{ return true;
}
else
{
return false;
}
</script>
<script type="dojo/method" event="getChildren" args="item, onComplete">
//
if(item.root){
return store.fetch({query: {type:'root'}, onComplete: onComplete});
}
else{
var itemtype = store.getValue(item, "type");
//write code for async call here
var pInfo = item ? {parent: item, attribute:"children"} : null;
console.debug(pInfo);
//id: '2',type:'Citrus', hasChild:true, name: 'Orange', children: [ ]
store.newItem({
id: 55,
type: "Citrus",
hasChild: false,
name: "nSomeProperty",
},pInfo);
console.log("item created");
return store.fetch({query: {type :store.getValue(item, "name")}, onComplete: onComplete});
}
//switch(item.root ? "top" : store.getValue(item, "type")){
//case "top":
// return store.fetch({query: {type:'root'}, onComplete: onComplete});
//case "root":
// return store.fetch({query: {type :store.getValue(item, "name")}, onComplete: onComplete});
// }
</script>
</div>
<div dojoType="dijit.Tree" jsId="myTree" id="myTree" model="model" showRoot="false" >
</div>
</body>
</html>
this actually is a try to create newItems at click of the plus so i can reach the server and add to data store new items, but its not working shome error says oldChildren have no properties pls help out
dino
dojo 1.1
ie6/ff2
error
oldChildren has no properties
(no name)([Object id=[1] type=[1] hasChild=[1] name=[1] top=[1], Object id=[1] type=[1] hasChild=[1] name=[1] top=[1]])dojo.js (line 1322)
(no name)([Object id=[1] type=[1] hasChild=[1] name=[1] top=[1], Object id=[1] type=[1] hasChild=[1] name=[1] top=[1]], Object query=Object store=Object)dojo.js (line 102)
(no name)(Object query=Object store=Object, [Object id=[1] type=[1] hasChild=[1] name=[1] top=[1], Object id=[1] type=[1] hasChild=[1] name=[1] children=[2], Object id=[1] type=[1] hasChild=[1] name=[1] children=[0], 4 more...])dojo.js (line 277)
(no name)(Object query=Object store=Object, function(), function())dojo.js (line 295)
(no name)(Object query=Object store=Object)dojo.js (line 105)
(no name)()dojo.js (line 1318)
(no name)(Object _S=Object _0=7 id=[1] _RRM=Object type=[1], Object item=Object attribute=children oldValue=[2])dojo.js (line 1337)
log()dojo.js (line 20)
log()dojo.js (line 20)
(no name)(Object id=55 type=Citrus hasChild=false name=nSomeProperty, Object parent=Object attribute=children)dojo.js (line 203)
(no name)()dojo.js (line 158)
(no name)([Widget dijit._TreeNode, dijit__TreeNode_1] _connects=[1] _attaches=[0] params=Object)dojo.js (line 775)
(no name)(Object node=[Widget dijit._TreeNode, dijit__TreeNode_1])dojo.js (line 702)
(no name)(click clientX=0, clientY=0)dojo.js (line 680)
log()
Json file --
<xml>
{
identifier: 'id',
label: 'name',
items: [
{ id: '0',type:'root', hasChild:true, name: 'Fruits', top: true, children: [ {_reference: 1}, {_reference: 4} ] },
{ id: '1',type:'Fruits', hasChild:true, name: 'Citrus',
children: [
{_reference: 2},
{_reference: 3}
]
},
{ id: '2',type:'Citrus', hasChild:true, name: 'Orange', children: [ ]},
{ id: '3',type:'Citrus', hasChild:false, name: 'Lemon'},
{ id: '4',type:'Fruits', hasChild:false, name: 'Tomato'},
{ id: '5',type:'root', hasChild:true, name: 'Vegetables', top: true, children: [ {_reference: 4} ] },
{ id: '6',type:'Vegetables',hasChild:false, name: 'Lettuce'}
]
}
(no name)([Object id=[1] type=[1] hasChild=[1] name=[1] top=[1], Object id=[1] type=[1] hasChild=[1] name=[1] top=[1]])dojo.js (line 1322)
(no name)([Object id=[1] type=[1] hasChild=[1] name=[1] top=[1], Object id=[1] type=[1] hasChild=[1] name=[1] top=[1]], Object query=Object store=Object)dojo.js (line 102)
(no name)(Object query=Object store=Object, [Object id=[1] type=[1] hasChild=[1] name=[1] top=[1], Object id=[1] type=[1] hasChild=[1] name=[1] children=[2], Object id=[1] type=[1] hasChild=[1] name=[1] children=[0], 4 more...])dojo.js (line 277)
(no name)(Object query=Object store=Object, function(), function())dojo.js (line 295)
(no name)(Object query=Object store=Object)dojo.js (line 105)
(no name)()dojo.js (line 1318)
(no name)(Object _S=Object _0=7 id=[1] _RRM=Object type=[1], Object item=Object attribute=children oldValue=[2])dojo.js (line 1337)
log()dojo.js (line 20)
log()dojo.js (line 20)
(no name)(Object id=55 type=Citrus hasChild=false name=nSomeProperty, Object parent=Object attribute=children)dojo.js (line 203)
(no name)()dojo.js (line 158)
(no name)([Widget dijit._TreeNode, dijit__TreeNode_1] _connects=[1] _attaches=[0] params=Object)dojo.js (line 775)
(no name)(Object node=[Widget dijit._TreeNode, dijit__TreeNode_1])dojo.js (line 702)
(no name)(click clientX=0, clientY=0)dojo.js (line 680)
log()
Json file --
<xml>
{
identifier: 'id',
label: 'name',
items: [
{ id: '0',type:'root', hasChild:true, name: 'Fruits', top: true, children: [ {_reference: 1}, {_reference: 4} ] },
{ id: '1',type:'Fruits', hasChild:true, name: 'Citrus',
children: [
{_reference: 2},
{_reference: 3}
]
},
{ id: '2',type:'Citrus', hasChild:true, name: 'Orange', children: [ ]},
{ id: '3',type:'Citrus', hasChild:false, name: 'Lemon'},
{ id: '4',type:'Fruits', hasChild:false, name: 'Tomato'},
{ id: '5',type:'root', hasChild:true, name: 'Vegetables', top: true, children: [ {_reference: 4} ] },
{ id: '6',type:'Vegetables',hasChild:false, name: 'Lettuce'}
]
}

up...
Do anybody know this problem???
Thanks
Dojo 1.1.1 Tree new item creation
Hi! I am using this code to load and create tree items in dojo v1.1.1.
dojo.require("dijit.Tree");
function createNewItem(categoryItem){
//append new node to selected item (categoryItem)
var kermit = categoriesTree.newItem({"name": 'test', "nodeid":1, "type":'category', query: {top:true}}, {parent:categoryItem, attribute:'children'});
//Expand parent node...
var idNode = ptTree.model.getIdentity(categoryItem);
var existingNode = ptTree._itemNodeMap[idNode];
existingNode.expand();
return true;
}
<div dojoType="dijit.Tree" store="categoriesTree" labelAttr="name" label="Categories" jsid="ptTree">
<script type="dojo/method" event="onClick" args="item">
createNewItem(item);
</script>
</div>
Data file tree_data.txt is something like this:
{"identifier":"nodeid","label":"name","items":[{.....}, {...},....]}
hope this helps!