简体   繁体   中英

dojo: Cannot read property 'appendChild' of null

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM