×
Vytvárame riešenia

Error: parser returned unfilled promise (Dojo)

Pri tvorbe widgetov môže programátor naraziť na chybové hlásenie parser returned unfilled promise (probab…load all supporting widgets before instantiation. Toto hlásenie súvisí s použitým templatom, ktorý obsahuje widgety. Uvedenú situáciu budem demonštrovať na nasledujúcom príklade.
Príklad: Zápis do elementu <body>.
1
<div data-dojo-type="my-widget"></div>
Príklad: Zápis do elementu <script>
1
2
3
4
5
require(["dojo/ready", "my-widget", "dojo/parser"], function(ready, parser) {
ready(function() {
});
});
Príklad: Súbor template.html.
1
2
3
<div>
<div data-dojo-type="dijit/form/TextBox" name="field"></div>
</div>
Príklad: Súbor my-widget.js.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
define([
"dojo/_base/declare",
"dijit/_Widget",
"dijit/_TemplatedMixin",
"dijit/_WidgetsInTemplateMixin",
"dojo/text!./template.html"
],
function(declare,
_Widget,
_TemplatedMixin,
_WidgetsInTemplateMixin,
template)
{
return declare("my-widget",
[_Widget, _TemplatedMixin, _WidgetsInTemplateMixin],
{
templateString: template,
startup: function() {
this.inherited(arguments);
}
});
});
Dôvodom chybového hlásenia je použitie widgetu TextBox v template pričom v súbore my-widget.js nie je definovaný. Zápisom widgetu TextBox do funkcie define() sa chybové hlásenie odstráni.
Príklad: Správny obsah súboru my-widget.js.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
define([
"dojo/_base/declare",
"dijit/_Widget",
"dijit/_TemplatedMixin",
"dijit/_WidgetsInTemplateMixin",
"dojo/text!./template.html",
"dijit/form/TextBox"
],
function(declare,
_Widget,
_TemplatedMixin,
_WidgetsInTemplateMixin,
template)
{
return declare("my-widget",
[_Widget, _TemplatedMixin, _WidgetsInTemplateMixin],
{
templateString: template,
startup: function() {
this.inherited(arguments);
}
});
});

Záver

Demonštrovaná chyba sa nemusí vždy prejaviť. Napríklad ak ide o vnorený template, kde widget TextBox už bol raz definovaný.


Dojo,parser,widget,auto-load
Žiadna časť tohto článku nesmie byť reprodukovaná bez uvedenia autora a URL na túto stránku.
Viac informácií nájdete v sekcii O projekte.

Komentáre

Článok neobsahuje zatiaľ žiadne komentáre.

Pridať komentár

Meno (povinné)
Web
Správa (povinné)
Odoslať
Od najnovších