[Dojo-interest] bug in dijit.Tree?

Bin Hu bhu at unm.edu
Fri Aug 1 06:37:01 UTC 2008


This discussion is more suited under the topic of dijit.Tree.

Bin

Begin forwarded message:

> From: "Jared Jurkiewicz" <jared.jurkiewicz at gmail.com>
> Date: July 31, 2008 1:30:08 PM GMT-07:00
> To: dojo-interest at dojotoolkit.org
> Subject: Re: [Dojo-interest] ItemFileWriteStore error
> Reply-To: dojo-interest at dojotoolkit.org
>
> This appears to be a problem with dijit.Tree.  It's holding onto the
> old instance (deleted) object, even when a new one is created by
> newItem.  Effectively the Tree isn't clearing its cache.   See
> testcase below:
> <!--
>  This file is a demo of multiple dojo.data aware widgets using
> different datastore implementations for displaying data.
> -->
> <html>
> <head>
> 	<title>Test of deleting and recreating children</title>
> 	<style type="text/css">
> 		@import "dijit/themes/tundra/tundra.css";
> 		@import "dojo/resources/dojo.css";
> 		@import "dijit/tests/css/dijitTests.css";
> 	</style>
>
> 	<script type="text/javascript" src="dojo/dojo.js" djConfig="isDebug:
> true, parseOnLoad: true"></script>
> 	<script type="text/javascript">
> 		dojo.require("dojo.parser");
> 		dojo.require("dijit.Tree");
>        dojo.require("dijit.form.Button");
> 		dojo.require("dojo.data.ItemFileWriteStore");
>
>        data = {
>            identifier: "name",
>            label: "name",
>            items: [
> 				{name:"Father", children: [{name: "Son1"},{name: "Son2"},{name:
> "Son3"},{name: "Son4"}]},
> 				{name:"Mother", children: [{name: "Daughter1"},{name:
> "Daughter2"},{name: "Daughter3"},{name: "Daughter4"}]}
>            ]
> 		}
>        myStore = new dojo.data.ItemFileWriteStore({data: data});
>        myStore.onNew = function(item, parentInfo) {
>            console.debug("Item: ", item);
> 			console.debug("Parent: ", parentInfo.item);
> 		}
>
> 		function init() {
> 			var deleteButton = dijit.byId("DeleteSon3Button");
> 			var createButton = dijit.byId("CreateSon3Button");
>
> 			function deleteSon3() {
> 				function onItem (item, request) {
>                    console.debug(item);
>                    myStore.deleteItem(item);
>                    myStore.save({onComplete: function() 
> {alert("Saved")}});
> 				}
>                myStore.fetchItemByIdentity({identity: "Son3",  
> onItem: onItem})
> 			}
>
> 			function createSon3() {
> 				function onItem (item, request) {
> 					myStore.newItem({name: "Son3"}, {parent: item, attribute:  
> "children"});
>                    myStore.save({onComplete: function() 
> {alert("Saved")}});
> 				}
> 				myStore.fetchItemByIdentity({identity: "Father", onItem: onItem});
> 			}
>            dojo.connect(deleteButton, "onClick", deleteSon3);
> 			dojo.connect(createButton, "onClick", createSon3);
> 		}
>        dojo.addOnLoad(init);
>
> 	</script>
> </head>
>
> <body class="tundra">
> 	<h1>
> 		TEST:  Verifying items can be deleted, then recreated.
> 	</h1>
> 	<hr>
> 	<blockquote>
> 	<!--
> 		The store instances used by this demo.
> 	-->
> 	<b>Tree:</b><br>
> 	<div dojoType="dijit.Tree" id="tree1" label="name" store="myStore">
>        <script type="dojo/method" event="onClick" args="item">
>            console.debug(item);
>        </script>
>    </div>
> 	</blockquote>
>    <button id="DeleteSon3Button" dojoType="dijit.form.Button">Delete
> Son 3</button>
>    <button id="CreateSon3Button" dojoType="dijit.form.Button">Create
> Son 3</button>
> </body>
> </html>
>
>
> Please open up a defect in Dojo on dijit.Tree.
>
> -- Jared
>
> On Thu, Jul 31, 2008 at 3:07 PM, Bin Hu <bhu at unm.edu> wrote:
>> Thanks for the reply.
>>
>> The code looks like what you see in below. All savings can be
>> confirmed. However, if the new item has the same identifier as the
>> deleted item (as in below), click on the item's node on the tree will
>> generate an error (as seen in the end of this email).
>>
>> I am using an in memory json object as the data source of the store.
>> Not sure whether that could be the reason.
>>
>> Regards,
>> Bin
>>
>>
>> <script type="text/javascript">
>>    // in memory josnObj
>>    var myStore = new dojo.data.ItemFileWriteStore({data:jsonObj});
>> </script>
>>
>> <div dojoType="dijit.tree.ForestStoreModel" jsId="myModel"
>>     store="myStore"
>>     rootId="modelRoot" rootLabel="myRoot"
>>     childrenAttrs="children">
>> </div>
>>
>> <div dojoType="dijit.Tree" id="mytree"
>>     model="myModel" showRoot="true"
>>     openOnClick="true">
>>    <script type="dojo/method" event="onClick" args="item">
>>    // code to display contents based on item type
>>    // ........
>>    </script>
>> </div>
>>
>> // add a child to a parent.
>> myStore.fetchItemByIdentity( {
>>    identity: "Parent",
>>    onItem: function(item) {
>>       modelStore.newItem(
>>           {name:"aChild",
>>            type:'childNode'
>>           },
>>           {parent:item,attribute:'children'});
>>    }
>> });
>>
>> // save the store
>> myStore.save({
>>    onComplete(alert('saved'));
>> })
>>
>> // delete the child
>> myStore.fetchItemByIdentity( {
>>    identity: "aChild",
>>    onItem: function(item) {
>>       modelStore.deleteItem(item);
>>    }
>> });
>>
>> // save the store
>> myStore.save({
>>    onComplete(alert('saved'));
>> })
>>
>> // add a new child with the same identifier
>> myStore.fetchItemByIdentity( {
>>    identity: "Parent",
>>    onItem: function(item) {
>>       modelStore.newItem(
>>           {name:"aChild",
>>            type:'aNewChildNode'
>>           },
>>           {parent:item,attribute:'children'});
>>    }
>> });
>>
>> myStore.save({
>>    onComplete(alert('saved'));
>> })
>>
>>
>>
>>
>>
>>
>>
>> On Jul 31, 2008, at 8:37 AM, Jared Jurkiewicz wrote:
>>
>>> As always, providing a sample testcase demonstrating the issue would
>>> allow for faster diagnosis.
>>>
>>>
>>>
>>> On Thu, Jul 31, 2008 at 11:35 AM, Jared Jurkiewicz
>>> <jared.jurkiewicz at gmail.com> wrote:
>>>> That is possibly a tree issue where it is holding reference to the
>>>> previous item instead of the newly created one.
>>>>
>>>>
>>>>
>>>> On Wed, Jul 30, 2008 at 8:40 PM, Bin Hu <bhu at unm.edu> wrote:
>>>>> Hi,
>>>>>
>>>>> I may have asked similar questions before but I still have not got
>>>>> an
>>>>> answer yet. I hope someone here can help me out on this problem.
>>>>>
>>>>> Basically, I create a new item in the ItemFileWriteStore then I
>>>>> delete
>>>>> that item with the save function and confirmed that the save is
>>>>> actually completed by using the onComplete callback function and  
>>>>> the
>>>>> isDrity() function. After that, I try to add a new item to the  
>>>>> store
>>>>> with exactly the same identifier. Although the new item can be  
>>>>> added
>>>>> (because it is displayed in the dijit.Tree) and saved (confirmed
>>>>> like
>>>>> above), if I click the new item's node in the tree, I will get an
>>>>> error message:
>>>>>
>>>>> Error: [Exception... "'Error: dojo.data.ItemFileReadStore: Invalid
>>>>> item argument.' when calling method:
>>>>> [nsIDOMEventListener::handleEvent]"  nsresult: "0x8057001c
>>>>> (NS_ERROR_XPC_JS_THREW_JS_OBJECT)"  location: "<unknown>"  data:  
>>>>> no]
>>>>>
>>>>> There is no problem if I just use another identifier for that same
>>>>> item.
>>>>>
>>>>> Can anyone point me out my error?
>>>>>
>>>>> Thanks.
>>>>> Bin
>>>>> _______________________________________________
>>>>> FAQ: http://dojotoolkit.org/support/faq
>>>>> Book: http://dojotoolkit.org/docs/book
>>>>> Forums: http://dojotoolkit.org/forum
>>>>> Dojo-interest at dojotoolkit.org
>>>>> http://turtle.dojotoolkit.org/mailman/listinfo/dojo-interest
>>>>>
>>>>
>>> _______________________________________________
>>> FAQ: http://dojotoolkit.org/support/faq
>>> Book: http://dojotoolkit.org/docs/book
>>> Forums: http://dojotoolkit.org/forum
>>> Dojo-interest at dojotoolkit.org
>>> http://turtle.dojotoolkit.org/mailman/listinfo/dojo-interest
>>
>> _______________________________________________
>> FAQ: http://dojotoolkit.org/support/faq
>> Book: http://dojotoolkit.org/docs/book
>> Forums: http://dojotoolkit.org/forum
>> Dojo-interest at dojotoolkit.org
>> http://turtle.dojotoolkit.org/mailman/listinfo/dojo-interest
>>
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://dojotoolkit.org/docs/book
> Forums: http://dojotoolkit.org/forum
> Dojo-interest at dojotoolkit.org
> http://turtle.dojotoolkit.org/mailman/listinfo/dojo-interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://turtle.dojotoolkit.org/pipermail/dojo-interest/attachments/20080731/0cb1031f/attachment.html 


More information about the Dojo-interest mailing list