0

我有以下子类,派生自 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;
    }
);

现在,以下代码在 "this.set("content", this.html);" 上引发 TypeError 线:

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

我应该如何正确设置 ContentPane 的内容?

4

1 回答 1

1

Ken Benjamin 在 Dojo 社区 (http://dojotoolkit.org/community/) 上回答了我的问题:

您试图在小部件生命周期中过早地设置内容。尝试在 postCreate 而不是构造函数中进行。

在此处阅读有关小部件生命周期的更多信息:http: //dojotoolkit.org/documentation/tutorials/1.6/understanding_widget/

于 2012-05-17T03:57:15.583 回答