1

我正在尝试从 dojo 网站扩展/修改一个示例,但遇到错误(使用 Firebug)并且不知道为什么。

这是在我的本地服务器上正常运行的原始教程:http: //dojotoolkit.org/documentation/tutorials/1.6/realtime_stores/demo/demo.html

现在我正在尝试添加一个 RequestMemory 存储:

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'
});         

... 跟原来的例子一样。

插入“RequestMemory”存储后,出现以下错误:

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

为什么?

4

1 回答 1

3

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.

于 2015-03-30T13:30:48.417 回答