Question

I have the following subclass, derived from ContentPane:

define([
        "dijit/layout/ContentPane",
        "dojo/_base/declare"
    ],

    function (ContentPane, declare) {
        var view = declare("client.View", ContentPane, {
            html: null,
            constructor: function (args) {
                declare.safeMixin(this, args);
                if (this.html !== null) {
                    this.set("content", this.html);
                }
            }
        });
        return view;
    }
);

Now, the following code throws TypeError on "this.set("content", this.html);" line:

var html = "<div>Hello</div>";
var view = View(html);

How should I set content of a ContentPane properly?

Was it helpful?

Solution

Ken Benjamin answered my question on Dojo Community (http://dojotoolkit.org/community/):

You are trying to set the content too early in the widget lifecycle. Try doing it in postCreate instead of constructor.

Read more about the widget lifecycle here: http://dojotoolkit.org/documentation/tutorials/1.6/understanding_widget/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top