Dijit combobox not rendering in custom widget

房东的猫 提交于 2019-12-11 10:17:49

问题


I am trying to use the combobox provided by Dijit inside of a custom-made widget. I have been using Dojo's tutorial on comboboxes to guide me.

When I implement a stand-alone webpage similar to their tutorial examples, everything worked fine; but when I ported the code into my custom-made widget, it just renders the combobox as a plain HTML text box.

Here's what my custom widget's template looks like:

<div class='customWidget'>
    ...

    <div dojoAttachPoint="mainDiv" class="mainDiv">
        <div dojoType="dojo.data.ItemFileReadStore" jsId="stateStore" url="states.txt"></div>

        <input dojoType="dijit.form.ComboBox"
               store="stateStore"
               value="California"
               searchAttr="name"
               name="state2" />

        <button dojoAttachEvent="onclick:chooseState">OK</button>
    </div>

    ...
</div>

In the widget code, I require the combobox and read store:

dojo.require("dijit.form.ComboBox");
dojo.require("dojo.data.ItemFileReadStore");

I also tried putting these includes in a <script/> within the custom widget (similar to the way they do it in the tutorial), but it didn't work (in fact, it appears as if the script tag wasn't even evaluated, since I couldn't reference a function I declared inside of it!)


回答1:


Do you have widgetsInTemplate in your widget declaration?

  dojo.declare('my.widget.Cool',[ dijit._Widget, dijit._Templated ], {

      widgetsInTemplate: true,

      // rest of widget JS here

   });

Here's an article about including other widgets in your template.




回答2:


Have you tried adding:

<script type="text/javascript">
    dojo.require("dojo.parser");
    dojo.addOnLoad(function(){
        dojo.parser.parse();
    });
</script>

(from Dojocampus) to ensure Dojo is parsing the page? Are there any errors in your Javascript console? Is the page rendering any normal Dojo widgets?



来源:https://stackoverflow.com/questions/1131814/dijit-combobox-not-rendering-in-custom-widget

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!