我正在研究一个 dojo 网格,这是新的 dojo dgrid,但我通过调用 html 标记文件上的 id 使 dgrid 工作,但我需要创建一个小部件,类似于将我的网格放入其中并能够访问的东西它通过 html 使用 dojotype。
我花了大约三天的时间来解决这个问题,但由于某种原因,如果我在我创建的小部件中声明它,我的网格不会显示。
下面是我的代码示例:
require([
"dojo/_base/declare", "dojo/dom-construct", "dojo/parser", "dojo/ready",
"dijit/_WidgetBase", "dijit/_TemplatedMixin", "dgrid/Grid", "dgrid/Keyboard",
"dgrid/Selection","dojo/text!./templates/dumHTML.html", "dojo/domReady!"
], function(declare, domConstruct, parser, ready, _WidgetBase, _TemplatedMixin, Grid, Keyboard, Selection, template) {
declare("Grid", [_WidgetBase, _TemplatedMixin], {
templateString: template,
widgetsInTemplate: true,
postCreate: function() {
var self = this;
this.inherited(arguments);
this._showGrid();
},
_showGrid: function() {
//json data string
var gridData =[
{'id': '10', 'filename':'budget.pdf','icon':'pdf'},
{'id': '20', 'filename':'thevampirediary.avi','icon':'xsl'},
{'id': '30', 'filename':'budget2.xsl','icon':'xsl'},
{'id': '40', 'filename':'budget3.doc','icon':'doc'},
{'id': '50', 'filename':'thevampirediary.avi','icon':'xsl'}
];
// Create a new constructor by mixing in the components
var DGrid = declare([Grid, Keyboard, Selection]);
var grid = new DGrid( {
columns: {
ID: {
label: " ",
field: "id",
hidden: true,
sortable: false,
formatter: function(id) {
return '<div style="visibility: hidden>'+id+' </div>';
}
},
filename: {
field: "filename",
label: "File name",
sortable: true,
formatter: function(filename) {
return '<div style="float:left ">'+filename+' </div>';
}
},
icon: {
field: "icon",
label:" ",
sortable: false,
formatter: function(icon) {
return '<img src="resources/' + icon + '.png" width="20px" hieght="20px"/>';
}
}
},
// for Selection; only select a single row at a time
selectionMode: "single",
// for Keyboard; allow only row-level keyboard navigation
cellNavigation: true
}, "grid");
grid.renderArray(gridData);
}
});
ready( function() {
// Call the parser manually so it runs after our widget is defined,
// and page has finished loading
parser.parse();
});
});