我正在开发一个dojo网格,这是新的dojo dgrid,但是我通过在html标记文件上调用id来使用dgrid,但是我需要创建一个小部件,就像我的网格中的网格一样能够使用dojotype通过html访问它。
我花了三天时间研究它,但出于某种原因,如果我在我创建的小部件中声明它,我的网格将无法显示。
下面是我的代码示例:
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();
});
});
答案 0 :(得分:1)
我只是dgrid的初学者,遇到了同样的问题。阅读本文后,我解决了这个问题。 https://github.com/SitePen/dgrid/wiki/Working-with-Widgets 解决方案是:在Dgrid实例中混合DijitRegistry。
这是我的代码。希望它对初学者有所帮助。 ModuleWithGuideBar 是我的自定义小部件(使用TemplatedMixin,_WidgetsInTemplateMixin声明)。
define([
"dojo/_base/declare",
"dijit/registry",
"common/widget/ModuleWithGuideBar",
"dgrid/OnDemandGrid",
"dgrid/Keyboard",
"dgrid/Selection",
"dgrid/extensions/DijitRegistry",
"dojo/store/Memory",
"dijit/layout/ContentPane"
], function (declare, registry, ModuleWithGuideBar, OnDemandGrid, Keyboard, Selection, DijitRegistry, Memory, ContentPane) {
return declare("app.management.module.event", [ModuleWithGuideBar], {
class:"module_event",
_grid:null,
postCreate:function () {
this.inherited(arguments);
var gridContainer = new ContentPane({region:'center'});
//add to data-dojo-attach-point
this.moduleContent.addChild(gridContainer);
var memoryStore = new Memory({data:[
{ first:"Bob", last:"Barker", age:89 },
{ first:"Vanna", last:"White", age:55 },
{ first:"Pat", last:"Sajak", age:65 }
]});
this._grid = new declare([OnDemandGrid, Keyboard, Selection, DijitRegistry])({
columns:{
first:{ label:"first" },
last:{ label:"last" },
age:{ label:"age" }
},
store:memoryStore
});
gridContainer.addChild(this._grid);
}
});
});