Dojox/app:是否有可能以编程方式定义视图?

Dojox/app: Is it possible to define views programatically

本文关键字:方式 编程 定义 视图 有可能 app 是否 Dojox      更新时间:2023-09-26

是否有可能以编程方式编写视图而不是使用html模板?我看到的所有演示都使用html模板。

这是可能的。添加HTML标记作为属性templateString的字符串,对于您的问题,下面的代码没有使用.html模板。您可以使用字符串连接,以便以编程方式修改模板。

关于templateString的更多信息请点击此处。

下面的例子来自用户Ben对我以前的一个问题的回答:

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>

你也可以在你的HTML模板中使用占位符,在模板中定义基本的标签结构,并从JS端为占位符提供值。

,

<div>
<div data-dojo-type="dojox.layout.contentpane" >
{content}
</div>
</div>

你也可以从postMixInProperties()动态修改一些HTML模板"

请参阅Widget生命周期以获得有关此方面的一些信息http://dojotoolkit.org/reference-guide/1.10/dijit/_WidgetBase.html