Search code examples
javascriptdojoextend

Dojo: There are something about 'class extend'?


I want to make a new widget javascript class [Label] it look like dijit.button. So I look at the source code of dijit Button and try to copycat it.

It start with declare and I use dijit.form._FormWidget as a superclass.

But when I run it on the web page it doesn't work, I debug with Firebug in Firefox and it return "this.containerNode is null"

I can't figure how to set containerNode parameter.

Can anyone answer me, what the problem does it cause it to happen?

P.S. I'm a bit new to javascript.


Solution

  • A simple dijit for your reference. The JavaScript:

    dojo.declare("com.example.Label", [dijit._Widget, dijit._Templated], {
        templateString: dojo.cache("com.example", "templates/Label.html"),
        value : ""
    });
    

    The HTML template:

    <div><span>${value}</span></div>
    

    Usage:

    var label = new com.example.Label({value : "Hello"});