Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#5545 closed defect (worksforme)

dojo.data.ItemFileReadStore not accepting data keyword in constructor

Reported by: guest Owned by: Jared Jurkiewicz
Priority: high Milestone:
Component: Data Version: 1.0
Keywords: Cc:
Blocked By: Blocking:

Description

I am testing out an upgrade to dojo 1.0.2 and I ran into a problem using loaded JSON data to instantiate an item store. I found a thread online that shows the same problem but no answer:

http://www.nabble.com/data-store-td14248070.html

The code example given apparently worked for one person but, like myself, not for the person using 1.0.2:

dojo.require('dojo.data.ItemFileReadStore');
var data = {data: {
    identifier : 'id',
    items : [
      { id : 'a', label: "Letter A" },
      { id : 'b', label: "Letter B" },
      { id : 'c', label: "Letter C" },
      { id : 'd', label: "Letter D" }
    ]
  }};

var myNewStore=new dojo.data.ItemFileReadStore(data);

I made a similar example which also fails:

var imgCtx = {data: {identifier:'item_id', items:[{item_id:1,title:'title',caption:'cap',alt_text:'alt',credits:'cred',height:'100',width:'200'}]}};
    var db = new dojo.data.ItemFileReadStore(imgCtx);

The current online Dojo documentation indicates that the "data" constructor keyword is supported but either of the above 2 examples return empty item stores. This seems like a bug.

I am using

Firefox 2.0.0.11 Mac OS 10.4.11 Dojo 1.0.2 The above examples were tested using the Firebug Mozilla plugin.

Attachments (1)

test.html (2.6 KB) - added by Jared Jurkiewicz 12 years ago.
And here's the example code I used. Just DL and drop into the root of a doko build and load it in a browser. It shows the data constructor option working fine. So, my guess is whatever you're doing around the store is incorrect.

Download all attachments as: .zip

Change History (3)

comment:1 Changed 12 years ago by Jared Jurkiewicz

Resolution: worksforme
Status: newclosed

The store works fine as far as I can tell, even using your example code (plus the many projects I know of at my company which use it in this manner).

I was able to take your code, unmodified, and fetch over it, getting out your item and its values. The only problem I see with your example is you pass the object in, but you never actually do anything with it. Where is your fetch call to query across it to access the items? Note that the data you pass in isn't even injected into store structures until the first fetch() or fetchByIdentity(), it's lazy-loading, effectively.

Here's what I did: <html> <head>

<title>Test of data loading ItemFileReadStore?</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, usePlainJson: true"></script> <script type="text/javascript">

dojo.require("dojo.data.ItemFileReadStore?"); function init(){

var imgCtx = {data: {identifier:'item_id', items:[{item_id:1,title:'title',caption:'cap',alt_text:'alt',credits:'cred',height:'100',width:'200'}]}};

var db = new dojo.data.ItemFileReadStore?(imgCtx);

function gotItems1(items, request){

document.body.appendChild(document.createTextNode("Adding in the values for all items for store named 'db':")); document.body.appendChild(document.createElement("br")); for(var i = 0; i < items.length; i++){

document.body.appendChild(document.createTextNode(db.getValue(items[i], "title"))); document.body.appendChild(document.createElement("br")); document.body.appendChild(document.createTextNode(db.getValue(items[i], "width"))); document.body.appendChild(document.createElement("br")); document.body.appendChild(document.createTextNode(db.getValue(items[i], "height")));

} document.body.appendChild(document.createElement("br"));

} function onError(error, request){

alert(error); console.debug(error);

}

var request = db.fetch({query:{}, onComplete: gotItems1, onError: onError});

var data = {data: {

identifier : 'id', items : [

{ id : 'a', label: "Letter A" }, { id : 'b', label: "Letter B" }, { id : 'c', label: "Letter C" }, { id : 'd', label: "Letter D" }

]

}};

var store2 = new dojo.data.ItemFileReadStore?(data); function gotItems2(items, request){

document.body.appendChild(document.createTextNode("Adding in the values for all items for store named 'store2':")); document.body.appendChild(document.createElement("br")); for(var i = 0; i < items.length; i++){

document.body.appendChild(document.createTextNode(store2.getValue(items[i], "id"))); document.body.appendChild(document.createElement("br")); document.body.appendChild(document.createTextNode(store2.getValue(items[i], "label"))); document.body.appendChild(document.createElement("br"));

} document.body.appendChild(document.createElement("br"));

} var request2 = store2.fetch({query:{}, onComplete: gotItems2, onError: onError});

}

dojo.addOnLoad(init); </script>

</head>

<body class="tundra"> </body>

comment:2 Changed 12 years ago by Jared Jurkiewicz

And the result in the browser from the was the following:

Adding in the values for all items for store named 'db': title 200 100 Adding in the values for all items for store named 'store2': a Letter A b Letter B c Letter C d Letter D

Far as I can tell, it accepts data in the constructor fine. My guess is your problem is in usage somewhere. Since your example doesn't show how you are doing a 'fetch' across the store, I cannot tell you what you have done wrong there.

Changed 12 years ago by Jared Jurkiewicz

Attachment: test.html added

And here's the example code I used. Just DL and drop into the root of a doko build and load it in a browser. It shows the data constructor option working fine. So, my guess is whatever you're doing around the store is incorrect.

Note: See TracTickets for help on using tickets.