我正在尝试从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({});
为什么?
答案 0 :(得分:3)
您似乎正在尝试将dstore与dgrid 0.3一起使用。这不会起作用,这就是你得到这个错误的原因(dgrid试图调用dstore中不存在的dojo / store query
API)。 dgrid在0.4中切换到dstore。
您有3个选项:
编辑:根据对问题和相关教程的更多内容,很明显,对query
的调用可能不是来自dgrid,而是来自复制的代码 - 从教程中添加(未包含在上面的问题中)。
鉴于有问题的教程使用dojo / store但dgrid 0.4使用dstore,你将无法简单地复制粘贴信息,但dgrid 0.4有store tutorial而dstore有{{3它自己的,包括它自己的实时商店教程版本。