我一直在努力创建一个简单的模板化小部件,其中包含使用dojo的dgrid。这是我在plunker中的代码:
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/dojo/1.9.3/dijit/themes/claro/claro.css" />
</head>
<body class="claro">
<div id="myContainer"></div>
<script type="text/javascript">
var dojoConfig = {
async: true,
parseOnLoad: true,
packages: [{
name: 'dgrid',
location: '//cdn.rawgit.com/SitePen/dgrid/v0.3.16'
}, {
name: 'myApp',
location: window.location.href.replace(/\/$/, "")
}]
}
</script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/dojo/1.9.3/dojo/dojo.js"></script>
<script type="text/javascript">
require(["dojo/dom", "dojo/_base/array", "myApp/SimpleTemplatedGridWidget", "dojo/domReady!"], function(dom, arrayUtil, MyWidget) {
var widget = new MyWidget.placeAt(myContainer);
});
</script>
</body>
</html>
SimpleTemplatedGridWidget.js
define([
"dijit/registry",
"dojo/_base/declare",
"dgrid/OnDemandGrid",
"dgrid/extensions/DijitRegistry",
"dijit/_TemplatedMixin",
"dojo/text!./SimpleTemplate.html"
],
function (registry, declare, Grid, DijitRegistry, _TemplatedMixin, template) {
return declare([_WidgetBase, _TemplatedMixin], {
data : [
{ first: 'Bob', last: 'Barker', age: 89 },
{ first: 'Vanna', last: 'White', age: 55 },
{ first: 'Pat', last: 'Sajak', age: 65 }
],
columns : {
first: 'First Name',
last: 'Last Name',
age: 'Age'
},
CustomGrid : declare([Grid, DijitRegistry]),
postCreate: function() {
myGrid = new CustomGrid({
columns: columns,
idProperty: "id"
}, this.AttachGrid);
myGrid.renderArray(data);
myGrid.startup();
}
});
});
SimpleTemplate.html
<div data-dojo-attach-point='AttachGrid'></div>
我看到错误,无法在本地或在解密器中都破译。我可能会缺少什么?
您的代码中有严重错误,有些是javascript基础,有些是dojo。
您的验证码
var widget = new MyWidget.placeAt(myContainer);
应该
var widget = new MyWidget().placeAt(myContainer);
另外,myContainer
从广义上讲,我建议您使用dojo/dom
已经包含的内容,这会造成混淆
var widget = new MyWidget().placeAt(dom.byId('myContainer'));
现在,关于您的小部件,您的小部件正在扩展_WidgetBase
,但未包含在内,因此
define([
"dijit/registry",
"dojo/_base/declare",
"dgrid/OnDemandGrid",
"dgrid/extensions/DijitRegistry",
"dijit/_WidgetBase", //You are missing this module
"dijit/_TemplatedMixin",
"dojo/text!./SimpleTemplate.html"
],
function (
registry,
declare,
Grid,
DijitRegistry,
_WidgetBase, //Also include it here
_TemplatedMixin,
template
) {
扩展时,_TemplatedMixin
我们需要定义,templateString
该情况应为加载了模板dojo/text!....
或静态模板(在您的情况下)
return declare([_WidgetBase, _TemplatedMixin], {
templateString: template, //need to add
现在,您的postCreate
函数引用了许多未定义的变量,即查看您的代码,我假设您要获取小部件本身的属性,因此
postCreate: function() {
myGrid = new this.CustomGrid({
columns: this.columns,
idProperty: "id"
}, this.AttachGrid);
myGrid.renderArray(this.data);
myGrid.startup();
}
请注意,我已经添加this.
在前面columns
,data
和CustomGrid
;
already registered widget
所做的更改解决了您的大部分问题,仅剩下一个人抱怨我通过删除DijitRegistry
模块解决了该问题,因为我不知道它的作用和用途。
我建议您一些链接:
希望能帮助到你
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句