Dojo: TypeError: marketStore.query is not a function

1k Views Asked by At

I'm trying to extend/modify an example from the dojo website but running into an error (with Firebug) and don't know why.

This is the original tutorial which runs properly on my local server: http://dojotoolkit.org/documentation/tutorials/1.6/realtime_stores/demo/demo.html

Now I'm trying to add a RequestMemory store:

require([
'dojo/_base/declare',
'dojo/Deferred',
'dstore/Memory',
'dstore/RequestMemory',
'dstore/QueryResults',
'dgrid/Grid',
'dgrid/OnDemandGrid',
'dgrid/extensions/Pagination',
"dgrid/List", 
"dgrid/OnDemandGrid",
"dgrid/Selection", 
"dgrid/editor", 
"dgrid/Keyboard", 
"dgrid/tree", 
"dojo/_base/declare", 
"dojo/store/JsonRest", 
"dojo/store/Observable", 
"dojo/store/Cache", 
"dojo/store/Memory", 
"dojo/_base/Deferred", 
"dojo/query",
"dojo/dom", 
"dojo/dom-construct", 
"dojo/domReady!"
],

function (declare, Deferred, Memory, RequestMemory, QueryResults, Grid, OnDemandGrid, Pagination, Observable, JsonRest, query, dom, domConstruct) {

var data = [
{"name": "Dow Jones", "index": 12197.88, "date": new Date()},
{"name": "Nasdaq", "index": 2730.68, "date": new Date()},
{"name": "S&P 500", "index": 1310.19, "date": new Date()}
];

var store = new (declare(RequestMemory, {
fetchRange: function () {
// Override RequestMemory's fetchRange method with
// one that introduces a delay.
var dfd = new Deferred();
var promise = this.inherited(arguments);
promise.then(function (data) {
  // Add an artificial delay of 1 second
  setTimeout(function () {
  dfd.resolve(data);
  }, 1000);
});
return new QueryResults(dfd, {
  totalLength: promise.totalLength
  });
}
}))({
target: 'node_data.json'
});         

... following as in the original example.

After inserting the "RequestMemory" Store I'm getting the following error:

TypeError: marketStore.query is not a function
var results = marketStore.query({});

Why?

1

There are 1 best solutions below

2
Ken Franqueiro On

You seem to be trying to use dstore with dgrid 0.3. That isn't going to work, and is why you're getting that error (dgrid is trying to call the dojo/store query API which doesn't exist in dstore). dgrid switched to dstore in 0.4.

You have 3 options:

  • Use dgrid 0.4 with dstore
  • Use dgrid 0.3 with dstore using DstoreAdapter to convert the store to the dojo/store API
  • Use the original RequestMemory store from dojo-smore (which is based on the dojo/store API) instead

EDIT: Based on reading more into the question and the related tutorial, it's evident that perhaps the call to query isn't coming from dgrid, but rather from code that was copy-pasted from the tutorial (which wasn't included in the question above).

Given that the tutorial in question uses dojo/store but dgrid 0.4 uses dstore, you won't be able to simply copy-paste the information there, but dgrid 0.4 has a store tutorial and dstore has tutorials of its own, including its own version of the realtime stores tutorial.