问题
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ü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übersicht"
});
heading.placeAt('divNodes0','first');
来源:https://stackoverflow.com/questions/16398247/how-do-i-create-a-div-with-dojo-create