首先,我使用的是 dojo 1.1.0 和 dgrid 0.4.0。我正在创建一个带有一些 dgrids 的页面。一个网格尤其需要从 url 加载 JSON 数据并显示它。目前使用 RequestMemory 存储可以正常工作。然而,这是一个“记忆”存储。虽然这对其他一些人来说可能是微不足道的,但我需要找到一种方法来加载数据,因为它现在正在完成,然后在屏幕上添加一个刷新按钮,调用必要的函数/方法来从 url 重新加载数据和重新填充 dgrid。
JSON 数据来自格式如下的 url:
[{"id":1,"name":"trans1","username":"trans1","status":"Available","inactive":"no","checkedout":"false","details":"","assignedNum":"0","completedNum":"0","avgTime":"00:00","aaOn":true},{"id":2,"name":"trans2","username":"trans2","status":"Available","inactive":"no","checkedout":"false","details":"","assignedNum":"0","completedNum":"0","avgTime":"00:00","aaOn":true},{"id":3,"name":"trans3","username":"trans3","status":"Available","inactive":"no","checkedout":"false","details":"","assignedNum":"0","completedNum":"0","avgTime":"00:00","aaOn":false},{"id":4,"name":"trans4","username":"trans4","status":"Available","inactive":"no","checkedout":"false","details":"","assignedNum":"0","completedNum":"0","avgTime":"00:00","aaOn":false},{"id":5,"name":"trans5","username":"trans5","status":"Available","inactive":"no","checkedout":"false","details":"","assignedNum":"0","completedNum":"0","avgTime":"00:00","aaOn":false},{"id":6,"name":"trans6","username":"trans6","status":"Available","inactive":"no","checkedout":"false","details":"","assignedNum":"0","completedNum":"0","avgTime":"00:00","aaOn":false}]
您将在下面看到的 Require 实际上包含的不仅仅是这个网格......因此还有更多。
我不需要更新本地商店,也不想监视 url 的更改。我只是希望能够按需从 url 重新加载数据。
这是我目前用于初始加载网格(工作)的代码和我需要开始工作的刷新按钮。
require([ 'dojo/store/Observable' ,'dijit/Dialog', 'dijit/form/Select', 'dijit/form/MultiSelect', 'dijit/form/TextBox', 'dijit/layout/TabContainer', 'dijit/layout/ContentPane','dojo/request', 'dojo/request/xhr', 'dijit/form/ToggleButton', 'dijit/form/Button', 'dojo/parser', 'dojo/_base/declare', 'dgrid/Grid', 'dgrid/Selection', 'dgrid/Editor', 'dgrid/extensions/ColumnHider', 'dgrid/extensions/Pagination', 'dstore/RequestMemory', 'dijit/form/Select', 'dijit/registry','dojox/data/XmlStore', 'dojo/domReady!'], function (Observable, Dialog, Select, MultiSelect, TextBox, TabContainer, ContentPane, request, xhr, ToggleButton, Button, parser, declare, Grid, Selection, Editor, ColumnHider, Pagination, RequestMemory, Select, registry, XmlStore) {
//workers dgrid
var workersStore = new RequestMemory({ target: '/autoAssign/getWorkers.aa?TASKTYPE=transport&INACTIVE=FALSE' });
var workerGrid = new (declare([ Grid, Selection, Pagination, Editor, ColumnHider ]))({
collection: workersStore,
className: 'dgrid-autoheight',
id: 'workerGrid',
rowsPerPage: 6,
columns: {
name: 'Name',
username: {
label: 'username',
hidden: true
},
status: 'Status',
assignedNum: 'Assigned',
completedNum: 'Completed',
avgTime: 'Average',
aaOn: {
label: 'Auto Assign',
editor: 'checkbox',
}
}
}, 'gridNode');
workerGrid.on("dgrid-datachange",function(evt) {
var row = workerGrid.row(evt);
if (evt.cell.column.id == 'aaOn') {
var promise = request('/autoAssign/setUserAaStatus.aa?USERNAME='+row.data.username+'&TASKTYPE=transport&STATUS='+evt.value);
}
});
workerGrid.startup();
//Add refresh Button
var addRefreshButton = new Button({
label: "Refresh",
style: 'float:right;',
onClick: function(){
var promise = workersStore.fetch();
var result = promise.then(function(data){
workerGrid.set("collection", workersStore);
workerGrid.refresh();
alert("refresh pushed");
});
}
}, "refresh").startup();
}
[{"id":1,"name":"trans1","username":"trans1","status":"Available","inactive":"no","checkedout":"false","details":"","assignedNum":"0","completedNum":"0","avgTime":"00:00","aaOn":true},{"id":2,"name":"trans2","username":"trans2","status":"Available","inactive":"no","checkedout":"false","details":"","assignedNum":"0","completedNum":"0","avgTime":"00:00","aaOn":true},{"id":3,"name":"trans3","username":"trans3","status":"Available","inactive":"no","checkedout":"false","details":"","assignedNum":"0","completedNum":"0","avgTime":"00:00","aaOn":false},{"id":4,"name":"trans4","username":"trans4","status":"Available","inactive":"no","checkedout":"false","details":"","assignedNum":"0","completedNum":"0","avgTime":"00:00","aaOn":false},{"id":5,"name":"trans5","username":"trans5","status":"Available","inactive":"no","checkedout":"false","details":"","assignedNum":"0","completedNum":"0","avgTime":"00:00","aaOn":false},{"id":6,"name":"trans6","username":"trans6","status":"Available","inactive":"no","checkedout":"false","details":"","assignedNum":"0","completedNum":"0","avgTime":"00:00","aaOn":false}]
任何帮助将不胜感激。我以前使用 Dojo 的旧数据网格执行此操作,但似乎无法理解我在这里缺少的内容。