[Dojo-interest] can't create a new ItemFileWriteStore

Peter E Higgins dante at dojotoolkit.org
Fri Jul 17 11:18:49 EDT 2009


you are creating two ItemFileWriteStore's local to each call of test(),
so both the async onComplete's will fire. If you call it again with
3000, you will get 3.

var store;
function test(rnd){
    if(!store){
         store = new ItemFileWriteStore();
    }
    store.newItem();
}

will at least prevent making new stores for each call.

Regards,
Peter


czy11421 wrote:
> I want to create a new store inside a function. I did this below. But 
> weird thing is, the store is not a NEW store, when second time call this 
> function, it has the data  in the first call.
>
> function test(rnd){
>     var store = *new* dojo.data.ItemFileWriteStore({data: phaseItem});
>         var newItem = {phaseId: rnd};
>         store.newItem(newItem);     
>
>         var onCompleteFetch = function(items, request) {
>             for (var i = 0; i < items.length; i++){
>                 var item = items[i];
>                 alert(item.phaseId);
>             }          
>         };
>      
>         store.fetch({query: {}, onComplete: onCompleteFetch});
> }
>
> test("1000");
> test("2000"); // will output "1000" *AND* "2000", I expected it will 
> only output "2000", because it is a new object.
>
> Any solution ?
>
> Thanks.
> Edward
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://dojotoolkit.org/docs/book
> Forums: http://dojotoolkit.org/forum
> Dojo-interest at mail.dojotoolkit.org
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
>   


-- 
Peter E Higgins
Dojo Project Lead : http://dojotoolkit.org 



More information about the Dojo-interest mailing list