I have a problem in populating the items parameter of the onComplete method with data from the server. The response received from the server has the list of items, however, the items parameter is empty. Here is the response from the server:
{"games":[{"title":"Persona 3: FES","releaseDate":"Thu Apr 19 15:46:59 AST 2007","developer":"Atlus"
,"score":98},{"title":"Suikoden V","releaseDate":"Thu Mar 23 15:46
:59 AST 2006","developer":"Konami","score":95},{"title":"Xenogears","releaseDate":"Wed Feb 11 15:46:59
AST 1998","developer":"Squaresoft","score":98}]}
,"score":98},{"title":"Suikoden V","releaseDate":"Thu Mar 23 15:46
:59 AST 2006","developer":"Konami","score":95},{"title":"Xenogears","releaseDate":"Wed Feb 11 15:46:59
AST 1998","developer":"Squaresoft","score":98}]}
The code has a method loadGames that calls the store.fetch method of the QueryReadStore. The other two methods gotGames and gotError are used as call backs for the fetch method:
dojo.require("dojo.parser");
dojo.require("dijit.form.Button");
dojo.require("dojox.data.QueryReadStore");
// create an instance of QueryReadStore
var store = new dojox.data.QueryReadStore({
url: "GameDataProvider"
});
// define a function that is called once the response is retrieved
var gotGames = function(items, request){
console.info("gotGames.request: " + dojo.toJson(request));
console.info("gotGames.items.length: " + items.length);
for (var i = 0; i < items.length; i++) {
console.info(store.getValue("item: " + items[i]));
}
};
var gotError = function(error, request){
console.info("gotError.error: " + error);
console.info("gotError.request: " + request);
}
// define a loadGames method
function loadGames(){
store.requestMethod = "get";
store.fetch({
onComplete: gotGames,
onError: gotError
});
}
dojo.require("dijit.form.Button");
dojo.require("dojox.data.QueryReadStore");
// create an instance of QueryReadStore
var store = new dojox.data.QueryReadStore({
url: "GameDataProvider"
});
// define a function that is called once the response is retrieved
var gotGames = function(items, request){
console.info("gotGames.request: " + dojo.toJson(request));
console.info("gotGames.items.length: " + items.length);
for (var i = 0; i < items.length; i++) {
console.info(store.getValue("item: " + items[i]));
}
};
var gotError = function(error, request){
console.info("gotError.error: " + error);
console.info("gotError.request: " + request);
}
// define a loadGames method
function loadGames(){
store.requestMethod = "get";
store.fetch({
onComplete: gotGames,
onError: gotError
});
}
The html code has a simple button that calls the loadGames button:
<form id="gamesForm" method="get">
<button dojoType="dijit.form.Button" id="gridButton">
Load Games
<script type="dojo/method" event="onClick">
loadGames();
</script>
</button>
</form>
<button dojoType="dijit.form.Button" id="gridButton">
Load Games
<script type="dojo/method" event="onClick">
loadGames();
</script>
</button>
</form>
Am I doing something wrong here?
