是否可以以编程方式编写视图而不是使用 html 模板?我见过的所有演示都使用 html 模板。
问问题
48 次
2 回答
0
是的,有可能。将您的 HTML 标记添加为 property 的字符串templateString
,以下代码不使用 .html 模板作为您的问题。您可以使用字符串连接以编程方式修改您的模板。
require(['dijit/_WidgetBase', 'dijit/_TemplatedMixin', 'dojo/_base/declare', 'dojo/domReady!'], function(_WidgetBase, _TemplatedMixin, declare, domReady) {
//Foo represent any widget with template available in dojo
//replace by the widget you want to use
var Foo = declare([_WidgetBase, _TemplatedMixin], {});
var foo = new Foo({
templateString: '<div>This is my teemplate and ${bar}</div>',
bar: "this is added to the template"
});
foo.placeAt('layout');
});
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dijit/themes/claro/claro.css" media="screen">
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
<div id="layout"></div>
于 2015-07-13T11:07:30.333 回答
0
您还可以在 HTML 模板中使用占位符,在模板中定义基本标记结构,并从 JS 端为占位符提供值。
前任:
<div>
<div data-dojo-type="dojox.layout.contentpane" >
{content}
</div>
</div>
或者
您还可以从“postMixInProperties()”动态修改一些 HTML 模板
请参阅小部件生命周期以获取有关该 http://dojotoolkit.org/reference-guide/1.10/dijit/_WidgetBase.html的一些信息
于 2015-07-13T18:27:22.827 回答