与Dojo确认从JSP调用的对话框小部件有关的问题 [英] Issue with dojo confirm dialog widget called from jsp
问题描述
我有以下小部件:
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 $ c内部调用此小部件$ c>如下:
I am trying to invoke this widget from inside my jsp
as below:
<script>
require(["mywidgets/widget/FruitWidget"], function(FruitWidget) {
var fruitWidget = new FruitWidget();
fruitWidget.startMyFunction();
});
</script>
但是当30秒超时到期并且 showWarning
被调用时,出现以下错误:
But when 30 second timeout expires and showWarning
gets called, I get error as:
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
时未定义?
I am new to Dojo and not able to understand the issue. Why fruitWarningDialog
is undefined when it is mentioned as data-dojo-attach-point
in template ?
推荐答案
data-dojo-attach-point
是指DOM节点,而不是小部件本身。您将小部件附加到此节点,通常在 postCreate()
中。在您的情况下,可以直接调用show()函数:
The data-dojo-attach-point
refers to a DOM node, not the widget itself. You attach a widget to this node, typically in postCreate()
. In your case, you could call the show() function directly:
showWarning: function() {
this.show();
},
这篇关于与Dojo确认从JSP调用的对话框小部件有关的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!