我试图将特定html标记中的内容加载到Dojo内容窗格中,而不是替换整个内容窗格。我正在加载的html包括一个标记定义的小部件,我希望在加载新行时呈现该小部件。
因此,我有一个通过ajax动态填充的表,即:
<body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/dojo/1.5/dojo/dojo.xd.js"
djConfig="parseOnLoad: true, isDebug:true"></script>
<div id="table-pane" dojoType="dijit.layout.ContentPane">
<table class="test">
<tbody>
<tr><td>Name</td><td>Year</td><td>Age</td></tr>
<tr>
<td><span dojoType="dijit.InlineEditBox" editor="dijit.form.Textarea">Mike</span>
</td>
<td>2010</td>
<td>12</td>
</tr>
</tbody>
</table>
</div>
</body>
<script>
var html ='<tr><td><span dojoType="dijit.InlineEditBox" editor="dijit.form.Textarea">John</span></td><td>2011</td><td>22</td></tr>';
dojo.require("dijit.layout.ContentPane");
dojo.require("dijit.InlineEditBox");
dojo.require("dijit.form.Textarea");
dojo.addOnLoad(function(){
pane = dijit.byId("table-pane");
add_elem();
});
function add_elem(){
var node = $(".test tr:last");
node.after(html);
dojo.addOnLoad(function(){
//Here I want to initiate any widgets that haven't been initiated
pane.buildRendering();
});
}</script>如何在新的表行中呈现Dojo小部件?
发布于 2010-12-30 00:26:42
ContentPane将使用setContent呈现内容集中的小部件。如前所述,在使用dojoType添加节点之后,还可以将dojo解析器指向特定的DOM节点。但是,如果您在代码中做所有的事情,为什么不使用编程方法而不是声明性方法呢?
使用您的示例,这将变成,
<html>
<body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/dojo/1.5/dojo/dojo.xd.js"
djConfig="parseOnLoad: true, isDebug:true"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<div id="table-pane" dojoType="dijit.layout.ContentPane">
<table class="test">
<tbody>
<tr><td>Name</td><td>Year</td><td>Age</td></tr>
<tr>
<td><span dojoType="dijit.InlineEditBox" editor="dijit.form.Textarea">Mike</span>
</td>
<td>2010</td>
<td>12</td>
</tr>
</tbody>
</table>
</div>
<script>
var html ='<tr><td><span id="target">John</span></td><td>2011</td><td>22</td></tr>';
dojo.require("dijit.layout.ContentPane");
dojo.require("dijit.InlineEditBox");
dojo.require("dijit.form.Textarea");
dojo.addOnLoad(function(){
var node = $(".test tr:last");
node.after(html);
new dijit.InlineEditBox({
editor: "dijit.form.Textarea",
autoSave: true
}, dojo.byId('target'));
});
</script>
</body>
</html>如果您正在使用Dojo,那么您也可以使用dojo.query而不是jQuery来定位和操作节点。例如,
dojo.query(".test tr:last-child");发布于 2010-12-29 17:47:02
这应该会有帮助:dojo.parser.parse(domnode?)
但我认为某些小部件,比如dijit.layout.contentpane,会自动增强加载的dom片段。所包含的小部件必须是dojo.required之前!
https://stackoverflow.com/questions/4551118
复制相似问题