我有以下小部件:
FruitWidget.html
<div data-dojo-type="dijit/ConfirmDialog"
data-dojo-attach-point="fruitWarningDialog"
data-dojo-props="title:'Timeout Warning'"
data-dojo-attach-event="execute:printTimeout">
Press ok to print something!
</div>
FruitWidget.js
define([
"dojo/_base/declare",
"dijit/ConfirmDialog",
"dijit/_WidgetBase",
"dijit/_TemplatedMixin",
"dijit/_WidgetsInTemplateMixin",
"dojo/text!./templates/FruitWidget.html"
], function(declare, ConfirmDialog, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, template) {
return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
templateString: template,
showWarning: function() {
this.fruitWarningDialog.show();
},
checkForTimeout: function () {
console.log('check for timeout called!');
var self = this;
var timeUntilWarning = 30 * 1000; // 30 seconds
setTimeout(function() {
self.showWarning();
}, timeUntilWarning);
},
startMyFunction: function () {
this.checkForTimeout();
},
printTimeout: function () {
console.log('Timeout occurred!');
}
});
});
我正尝试从jsp
内部调用此小部件,如下所示:
<script>
require(["mywidgets/widget/FruitWidget"], function(FruitWidget) {
var fruitWidget = new FruitWidget();
fruitWidget.startMyFunction();
});
</script>
但是当30秒超时到期并且showWarning
被调用时,出现以下错误:
There was an error on this page.
Error: Uncaught TypeError: Cannot read property 'show' of undefined
URL: mywidgets/widget/FruitWidget/FruitWidget.js
我是Dojo的新手,无法理解该问题。为什么fruitWarningDialog
在模板中被称为data-dojo-attach-point
时未定义?
答案 0 :(得分:0)
data-dojo-attach-point
是指DOM节点,而不是窗口小部件本身。您将小部件附加到该节点,通常在postCreate()
中。就您而言,您可以直接调用show()函数:
showWarning: function() {
this.show();
},