dojo: Cannot read property 'appendChild' of null

785 views Asked by At

Here is my define's factory function:

declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
        widgetsInTemplate: true,
        templateString: FiltersTemplate,
        baseClass: 'gis_FiltersDijit',
        i18n: i18n,
        postCreate: function () {
            var pins = ['12-82-080', '04-52-080', '04-77-080'];
            for (p = 0; p < pins.length; p++) {
                var curBox = new CheckBox({
                    value: pins[p]
                });
                domConstruct.place(curBox, 'projPinFilter', 'last');
            }             
        }

CheckBox is 'dijit/form/CheckBox'

why am I getting this error? I am using dojo/domReady!.

Here is the relevant html:

<button data-dojo-type="dijit/form/DropDownButton">
                        <span>Proj. PIN</span>
                        <div id="projPinFilter"></div>
                    </button>

As you can see, I am trying to simulate populating a dropdown checkbox list with server values.

All advice is appreciated, thanks.

1

There are 1 answers

0
ben On

I think it is because the 1 arguments of domConstruct.place is expected to be a domNode. So curBox.domNode

I would rather use placeAt: curBox.placeAt('projPinFilter')

Note: 'last' is default.

If this doesn't help, try to add console.log(dom.byId('projPinFilter')) It should output the domNode you want to append to. If not, then dom is not yet ready (but it is unlikely because you are using dojo/domReady!