我不为此使用 ItemFileWriteStore !自 Dojo 1.6 以来,它们发生了很大变化,所以也许你看到了一些不是最新的东西。
试试这个代码:
// 加载必要的组件(这是 AMD 的 dojo)!
require(["dojo/aspect",'dojo/_base/lang', 'dojox/grid/DataGrid','dojo/dom', 'dojo/store/JsonRest','dojo/data/ObjectStore', 'dojo/ domReady!'],
function(aspect,lang, DataGrid, dom,JsonRest,ObjectStore){ // 将组件映射到 vars...
var store = new JsonRest({
target: "getJSON.php" // Use a URL that you can open up in a browser.
});
/*layout for the grid, you will have to adapt this to your columns !!!*/
var layout = [[
{'name': 'Filename', 'field': 'documentName', 'width': '300px'},
{'name': 'Size', 'field': 'fileSize', 'width': '100px'},
{'name': 'Id', 'field': 'id', 'width': '200px'}
]];
dataStore=ObjectStore({objectStore: store}); // Transform to Objectstore !
/*Now we create a new grid*/
var grid = new DataGrid({
id: 'grid',
store:dataStore, // Connect the store
autoWidth:false,
structure: layout, // Connect the layout
rowSelector: '0px'});
grid.placeAt("yourTargetDivId"); // Has to be an existing DOM Element with id !
grid.startup(); // START IT !
});
请先通过回显类似这样的简单内容来尝试此代码:
echo '[{"id":"1","fileSize":"100kb","documentName":"Lucian !"}, {"id":"2","fileSize":"900kb","documentName" :"皮尤皮尤!"}]';
然后用你自己的 JSON ......