How do i create a div with dojo create?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 05:41:32

问题


i want to generate the divNodes0 div from this example via dojo create (including the h1 and ul):

<body class="mobile">
    <div dojoType="dojox.mobile.View" id="mobileView">
        <div dojoType="dojox.mobile.ScrollableView" id="divNodes01" scrollDir="v" style="background-color: #d0d0d0;">
            <h1 dojoType="dojox.mobile.Heading" fixed="top" id="h1Nodes01"></h1>
            <ul id="ulNodes01" dojoType="dojox.mobile.RoundRectList"></ul>
        </div>
    </div>
[...]
</body>

i tried it this way (without sucess):

var mobileView = document.getElementById("mobileView");
dojo.create("div",{
            id: "divNodes0",
            dojoType: "dojox.mobile.ScrollableView",
            scrollDir: "v",
            style: "background-color: #d0d0d0"
            },
            mobileView,"first");


var mainNodeDiv = document.getElementById("divNodes0");
dojo.create("h1",{
            id: "h1Nodes0",
            dojoType: "dojox.mobile.Heading",
            back: "zurŸck",
            moveTo: "divNodes0",
            fixed: "top",
            label: "Knoten&uuml;bersicht"
            },
            mainNodeDiv,"first");

    dojo.create("ul",{
            id: "ulNodes0",
            dojoType: "dojox.mobile.RoundRectList"
            },
            mainNodeDiv);

greets Tom


回答1:


If you want to look up nodes by Id, you generally want to use dojo.byId('someId')

The third parameter to dojo.create can be either a domNode (like you are using) or an id of a dom node: dojo.create('h1',{},'divNodes0','first')

Based on your usage of the dojoType attribute it seems like you want to use "widgets" rather than dom nodes. Widgets are generally a template of domnodes with built in styling and event handling that are easily reusable. Instantiating and placing widgets is simple:

var heading = new dojox.mobile.Heading({
  id: "h1Nodes0",
  dojoType: "dojox.mobile.Heading",
  back: "zurŸck",
  moveTo: "divNodes0",
  fixed: "top",
  label: "Knoten&uuml;bersicht"
});
heading.placeAt('divNodes0','first');


来源:https://stackoverflow.com/questions/16398247/how-do-i-create-a-div-with-dojo-create

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