简体   繁体   English

Dojo的问题确认从JSP调用的对话框小部件

[英]Issue with dojo confirm dialog widget called from jsp

I have the following widget: 我有以下小部件:

FruitWidget.html 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 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!');
    }
 });
});

I am trying to invoke this widget from inside my jsp as below: 我试图从我的jsp内部调用此小部件,如下所示:

<script>
  require(["mywidgets/widget/FruitWidget"], function(FruitWidget) {
    var fruitWidget = new FruitWidget();
    fruitWidget.startMyFunction();
  });
</script>

But when 30 second timeout expires and showWarning gets called, I get error as: 但是,当30秒超时到期并且showWarning被调用时,我得到如下错误:

There was an error on this page.

Error: Uncaught TypeError: Cannot read property 'show' of undefined
URL: mywidgets/widget/FruitWidget/FruitWidget.js

I am new to Dojo and not able to understand the issue. 我是Dojo的新手,无法理解该问题。 Why fruitWarningDialog is undefined when it is mentioned as data-dojo-attach-point in template ? 为什么在模板fruitWarningDialog称为data-dojo-attach-point时未定义它?

The data-dojo-attach-point refers to a DOM node, not the widget itself. data-dojo-attach-point是指DOM节点,而不是窗口小部件本身。 You attach a widget to this node, typically in postCreate() . 您将小部件附加到此节点,通常在postCreate() In your case, you could call the show() function directly: 对于您的情况,可以直接调用show()函数:

showWarning: function() {
    this.show();
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM